cancel
Showing results for 
Search instead for 
Did you mean: 

looping problem with while loop in PHP

N/A

looping problem with while loop in PHP

I have a loop which i have modified from the example one given when you set up the cgi webspace. I have been able to modify the code so that i can arrange the row in a table, but i have only 2 records in the table and they are shown like 10 times in the page. Its obviously a problem with the code, but i have never done PHP before i have done ASP for nearly 2 years and i suppose i am quite proficient in it, but this is new and a little bit more confusing than the VBS used in ASP. Any help with the problem will be gratefully recieved.

the url to view the page is at http://cgi.srscaife.force9.co.uk/error_show.php

$chan = mysql_connect ($db_host, $username, $password);
mysql_select_db ($DB_name, $chan);

$resultid = mysql_query ("select * from Error", $chan);

echo "<table align='center' width='90%' border='0'>";
echo "<tr>";
echo "<td>Error Code</td><td>Product Name</td><td>Error Problem</td><td>Error Solution</td><td>Operating System</td>";
echo "</tr>";
while ($resultrow= mysql_fetch_row($resultid)) {

while (list($key,$value)=each($resultrow)) {
echo "<tr><td>$resultrow[0]</td><td>$resultrow[1]</td><td>$resultrow[2]</td><td>$resultrow[3]</td><td>$resultrow[4]</td></tr>";
}
}
?>
</table>

[Moderator's note (by csogilvie): Fixing BBCode Tag for you.]
1 REPLY
N/A

looping problem with while loop in PHP

You do not need the second while statement.
$chan = mysql_connect ($db_host, $username, $password);

mysql_select_db ($DB_name, $chan);

$resultid = mysql_query ("select * from Error", $chan);

echo "<table align='center' width='90%' border='0'>";
echo "<tr>";
echo "<td>Error Code</td><td>Product Name</td><td>Error Problem</td><td>Error Solution</td><td>Operating System</td>";
echo "</tr>";
while ($resultrow= mysql_fetch_row($resultid)) {

echo "<tr><td>$resultrow[0]</td><td>$resultrow[1]</td><td>$resultrow[2]</td><td>$resultrow[3]</td><td>$resultrow[4]</td></tr>";
}
?>
</table>