Uninitialized string offset

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
warriorforgod
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 11:16 am

Uninitialized string offset

Post by warriorforgod »

I am using the following code and trying to format this into a table, however I am getting the above stated error. Here is the code.

Code: Select all

 
for ($i=0;$i<count($req);$i++){
        $q="";
        for ($x=0;$x<=6;$x++){
                $q .= $req[$i][$x];
        }
        echo '<tr><td><a href="javascript&#058; openwindow(\'http://servicedesk.west.com/CAisd/pdmweb.exe?OP=SEARCH+FACTORY=cr+SKIPLIST=1+QBE.EQ.ref_num='.$q.'\')">'.$q.'</a></td><td>';
                $q="";
                for ($z=8;$z<=300;$z++){
                print_r($req[$i][$z]);
                }
echo '</td><td>';
                for ($b=0;$b<=300;$b++){
                print_r($sum[$i][$b]);
                }
echo '</td><td>';
                for ($c=0;$c<=300;$c++){
                print_r($aname[$i][$c]);
                }
echo '</td></tr>';
                for ($d=0;$d<=300;$d++){
                print_r($cname[$i][$d]);
                }
echo '</td></tr>';
                for ($e=0;$e<=300;$e++){
                print_r($dsc[$i][$e]);
                }
echo '</td></tr>';
}
 
 
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Uninitialized string offset

Post by mikemike »

Where is $req set? Does the error give you a line number?
warriorforgod
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 11:16 am

Re: Uninitialized string offset

Post by warriorforgod »

Figured this one out, however now I am facing a new challenge. I have a for loop to create my table that is populated with data pulled form a database. It seems that the loop is only running through once. Here is the code.

Code: Select all

 
echo "<tr>";
        for($i=1;$i<=odbc_num_fields($result5);$i++)
        {
                $q=odbc_result($result1,$i);
                echo '<td><a href="javascript&#058; openwindow(\'http://servicedesk.west.com/CAisd/pdmweb.exe?OP=SEARCH+FACTORY=cr+SKIPLIST=1+QBE.EQ.ref_num='.$q.'\')">'.$q.'</a></td>';
                echo "<td>";
                echo odbc_result($result2,$i);
                echo "</td>";
                echo "<td>";
                echo odbc_result($result3,$i);
                echo "</td>";
                echo "<td>";
                echo odbc_result($result4,$i);
                echo "</td>";
                echo "<td>";
                echo odbc_result($result5,$i);
                echo "</td>";
echo "</tr>";
        }
 
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Uninitialized string offset

Post by mikemike »

Again you're not giving us enough detail. It's only running once because odbc_num_fields($result5) is equal to or less than 1. I guess you need to work out why it's returning <= 1. It may be failing and returning -1. You'll have to do some basic debugging, try echoing odbc_num_fields($result5)...
warriorforgod
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 11:16 am

Re: Uninitialized string offset

Post by warriorforgod »

Hmm. output of echo odbc_num_fields($result5); is 1. Is it because I am not doing the odbc_exec statments in the for loop? I am connecting to an mssql 2005 db using freetds odbc connector if that helps anything. Here is the complete code for the page not including the database connection or the SQL querys.

Code: Select all

 
<?php
 
 
error_reporting(E_ALL);
 
$result1=odbc_exec($connect, $requests);
$result2=odbc_exec($connect, $summary);
$result3=odbc_exec($connect, $a_name);
$result4=odbc_exec($connect, $c_name);
$result5=odbc_exec($connect, $desc);
 
echo "<tr>";
    for($i=1;$i<=count($requests);$i++)
    {
        $q=odbc_result($result5,$i);
        echo '<td><a href="javascript&#058; openwindow(\'http://servicedesk.west.com/CAisd/pdmweb.exe?OP=SEARCH+FACTORY=cr+SKIPLIST=1+QBE.EQ.ref_num='.$q.'\')">'.$q.'</a></td>';   
        echo "<td>";    
        echo odbc_result($result2,$i);
        echo "</td>";
        echo "<td>";
        echo odbc_result($result3,$i);
        echo "</td>";
        echo "<td>";
        echo odbc_result($result4,$i);
        echo "</td>";
        echo "<td>";
        echo odbc_result($result5,$i);
        echo "</td>";
echo "</tr>";
echo odbc_num_fields($result5);   
    }
echo "</table>";
 
 
odbc_close($connect);
mssql_min_message_severity(16);
 
?>
</body>
</html>
 
Post Reply