Page 1 of 1

Uninitialized string offset

Posted: Thu Jun 04, 2009 9:54 am
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>';
}
 
 

Re: Uninitialized string offset

Posted: Thu Jun 04, 2009 12:38 pm
by mikemike
Where is $req set? Does the error give you a line number?

Re: Uninitialized string offset

Posted: Thu Jun 04, 2009 2:02 pm
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>";
        }
 

Re: Uninitialized string offset

Posted: Thu Jun 04, 2009 2:29 pm
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)...

Re: Uninitialized string offset

Posted: Thu Jun 04, 2009 2:39 pm
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>