Why does the word "Array" show on a select query

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I am new to php and MySQL and I'm attempting to run a select query on a
MySQL database which is working fine except prior to displaying the table
with the results from the select query it displays 1 line for each row in
the database containing only the word Array. This is then followed by the
correct results in the constructed table. I am not storing the string
"Array" in my table.

 Following is the PHP code for constructing the table from the results

               for ($i = 0; $i < mysql_num_rows($result); $i++)
                   echo "<tr>";
                   echo  $row = mysql_fetch_row($result);
                     for ($j = 0; $j < mysql_num_fields($result); $j++)
                       echo("<td>" . $row[$j] . "</td>");
                   echo "</tr>";

I hope this is enough of the PHP script to solve the problem



Re: Why does the word "Array" show on a select query

Never Mind I see the problem.  The statement "echo  $row =
mysql_fetch_row($result);" should not be an echo. It's amazing but the
solution to the problem is always clear within a few minutes after I post
the question.

Quoted text here. Click to load it

Re: Why does the word "Array" show on a select query

Line 4:
echo  $row = mysql_fetch_row($result);

That's your problem.

If you try to echo an array in php it will print "Array".
Try print_r($row) or var_dump($row) if you actually want to print the
array's contents



Site Timeline