Jump to content

endless loop help


Darkmatter5

Recommended Posts

Why would

$row=mysql_fetch_assoc($result);
echo "<table width='650' border='0'>";
echo "<tr>";
echo "<td colspan='2' class='row_description' align='left'>";
echo "<ol>";
while($row) {
  echo "<li><a href='editjobs.php?=" .$row['job_id']. "' >" .$row['job_number']. "</a>, " .$row['job_desc']. "</li>";
}
echo "</ol></td></tr></table>";

create an endless loop that prints out the <li> line endlessly, while

echo "<table width='650' border='0'>";
echo "<tr>";
echo "<td colspan='2' class='row_description' align='left'>";
echo "<ol>";
while($row=mysql_fetch_assoc($result)) {
  echo "<li><a href='editjobs.php?=" .$row['job_id']. "' >" .$row['job_number']. "</a>, " .$row['job_desc']. "</li>";
}
echo "</ol></td></tr></table>";

only outputs the specified results and the loop ends correctly?

Link to comment
https://forums.phpfreaks.com/topic/117169-endless-loop-help/
Share on other sites

$row=mysql_fetch_assoc($result);
echo "<table width='650' border='0'>";
echo "<tr>";
echo "<td colspan='2' class='row_description' align='left'>";
echo "<ol>";
while($m = $row) {
  echo "<li><a href='editjobs.php?=" .$m['job_id']. "' >" .$m['job_number']. "</a>, " .$m['job_desc']. "</li>";
}
echo "</ol></td></tr></table>";

Link to comment
https://forums.phpfreaks.com/topic/117169-endless-loop-help/#findComment-602657
Share on other sites

because the first one

 

while($row)

{

}

 

is always TRUE!!! it stays on the first row....you're not fetching any new rows in that loop...

 

try

 

print_r($row); // it should give the same variables over and over

 

 

and the second one...after it finishes the loop body it goes back to the while condition and $row is assigned a new one...when there arent any more rows mysql_fetch_assoc() return false...

Link to comment
https://forums.phpfreaks.com/topic/117169-endless-loop-help/#findComment-602658
Share on other sites

$row=mysql_fetch_assoc($result);
echo "<table width='650' border='0'>";
echo "<tr>";
echo "<td colspan='2' class='row_description' align='left'>";
echo "<ol>";
while($m = $row) {
  echo "<li><a href='editjobs.php?=" .$m['job_id']. "' >" .$m['job_number']. "</a>, " .$m['job_desc']. "</li>";
}
echo "</ol></td></tr></table>";

 

even this is endless.

try this..

echo "<table width='650' border='0'>";
echo "<tr>";
echo "<td colspan='2' class='row_description' align='left'>";
echo "<ol>";
while($row=mysql_fetch_assoc($result) {
  echo "<li><a href='editjobs.php?=" .$m['job_id']. "' >" .$row['job_number']. "</a>, " .$m['job_desc']. "</li>";
}
echo "</ol></td></tr></table>";

Link to comment
https://forums.phpfreaks.com/topic/117169-endless-loop-help/#findComment-602677
Share on other sites

to make the first one work is very simple..

 

$row=mysql_fetch_assoc($result);
echo "<table width='650' border='0'>";
echo "<tr>";
echo "<td colspan='2' class='row_description' align='left'>";
echo "<ol>";
while($row) {
  echo "<li><a href='editjobs.php?=" .$row['job_id']. "' >" .$row['job_number']. "</a>, " .$row['job_desc']. "</li>";
  $row=mysql_fetch_assoc($result); // just add this inside the loop
}
echo "</ol></td></tr></table>";

 

add this line inside the while loop which i did for you

$row=mysql_fetch_assoc($result)

Link to comment
https://forums.phpfreaks.com/topic/117169-endless-loop-help/#findComment-602682
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.