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

This is a discussion on Why does the word "Array" show on a select query within the PHP Language forums, part of the PHP Programming Forums category; Hello, I am new to php and MySQL and I'm attempting to run a select query on a MySQL ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2005
Vic Spainhower
 
Posts: n/a
Default Why does the word "Array" show on a select query

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



Reply With Quote
  #2 (permalink)  
Old 02-26-2005
Vic Spainhower
 
Posts: n/a
Default 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.



"Vic Spainhower" <vic@showsec.com> wrote in message
news:h6adnVp5VswyMb3fRVn-gg@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
>
>
>



Reply With Quote
  #3 (permalink)  
Old 02-26-2005
dourdoun@gmail.com
 
Posts: n/a
Default 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

Cheers

Vasilis

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:48 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0