By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,536 Members | 895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,536 IT Pros & Developers. It's quick & easy.

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

P: n/a
Hello,

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
variable.

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

TIA

Vic

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Cheers

Vasilis

Jul 17 '05 #2

P: n/a

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.

"Vic Spainhower" <vi*@showsec.com> wrote in message
news:h6********************@comcast.com...
Hello,

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
variable.

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

TIA

Vic

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.