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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vic Spainhower

    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_field s($result); $j++)
    {
    echo("<td>" . $row[$j] . "</td>");
    }
    echo "</tr>";
    }

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

    TIA

    Vic



  • dourdoun@gmail.com

    #2
    Re: Why does the word &quot;Array&quo t; 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

    Comment

    • Vic Spainhower

      #3
      Re: Why does the word &quot;Array&quo t; 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.co m> wrote in message
      news:h6adnVp5Vs wyMb3fRVn-gg@comcast.com. ..[color=blue]
      > 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_field s($result); $j++)
      > {
      > echo("<td>" . $row[$j] . "</td>");
      > }
      > echo "</tr>";
      > }
      >
      > I hope this is enough of the PHP script to solve the problem
      >
      > TIA
      >
      > Vic
      >
      >
      >[/color]


      Comment

      Working...