Jump to content

[SOLVED] LOOPS not working


rule69

Recommended Posts

Could some4 why this wont worK it returns a blank page..

 

<?php
do{


echo " <span>- <a href=\"news.php?go=view&id=$id\">$content</a> </span><br />";


}while(1 <= 4);
?>

 

btw i tried all the loops... for , while etc they either return EVERYTHNG from the db or it just returns a blank page after loading forever..i only want 4 results from the sql db..thanks

Link to comment
https://forums.phpfreaks.com/topic/104434-solved-loops-not-working/
Share on other sites

What 94470 was saying works too...you have to increment a counter in order for a while loop to work.

 

You had while(1<=4)

 

But 1 is ALWAYS less than 4...so it'll never stop =)

 

What you want is

 

<?php
$i=0;

while($i<=4){
echo $i."<br>"; 

$i++;
}
?>

 

This should give you a better example how a while loop works.

hmm thanks for that i thought that increment thng worked only for the for,foreach loops hmm i my consider that from now on... well i kinda changed the code again and used this instead then just limited the results on the sql query itself... which is what i used to do...

 

<?php
while($returned_data = mysql_fetch_row($result))
{
list($id,$descri,$content,$views,$date) = $returned_data;
  echo " <span>- <a href=\"news.php?go=view&id=$id\">$content</a> </span><br />";
}
?>

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.