On Thu,  8 Mar 2001 14:03, Deependra B. Tandukar wrote:
> Greetings!
>
> I am using PHP and MySQL in RedHat 6.0.
> I have used mysql_fetch_array() to display the datas in web page but
> all the columns are printed twice. What can be the wrong with my code:
> <?php
> $connection=mysql_connection(...............);
> $db=mysql_select_db(.....................);
> $sql="select * from my db";
> $sql_result=$mysql_query($sql,$connection);
> print "<table>";
> while ($row=mysql_fetch_array($sql_result))
>     {
>     print "<tr>";
>     foreach ($row as $field)
>         print "<td>$field</td>";
>     print "<td><a href=\"search.php?ID=$row[ID]\">";
>     print "Get it";
>     print "</a></td>";
>     print "</tr>";
>     }
> print "</table>";
> ?>
>
> But it works fine with mysql_fetch_row() however it does not pass the
> pass the variable ID.
>
> Looking forward to hearing from you.
>
> Warm regards,

First up, shouldn't you have {} to delineate what is actually the foreach 
procedure(s)?

I would suggest using extract within your While loop to make the table 
fields available as variables.

while ($row=mysql_fetch_array($sql_result))
  {
  extract($row);
  echo "<tr>";
  echo "<td>$field</td>"; \\ or whatever the field is called
  echo "<td><a href=\"search.php?ID=$ID\">";
  echo "Get it";
  echo "</a></td>";
  echo "</tr>";
  }


-- 
David Robley                        | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet                            | http://auseinet.flinders.edu.au/
            Flinders University, ADELAIDE, SOUTH AUSTRALIA

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to