rule69 Posted May 6, 2008 Share Posted May 6, 2008 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 More sharing options...
947740 Posted May 6, 2008 Share Posted May 6, 2008 You have to have an increment statement, do you not? Change the numbers to variables and add 1 each time through. I think that is what you need to do. Link to comment https://forums.phpfreaks.com/topic/104434-solved-loops-not-working/#findComment-534608 Share on other sites More sharing options...
rhodesa Posted May 6, 2008 Share Posted May 6, 2008 that is an infinite loop...i think what you are looking for is: <?php for($n = 0;$n < 4;$n++){ echo " <span>- <a href=\"news.php?go=view&id=$id\">$content</a> </span><br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/104434-solved-loops-not-working/#findComment-534609 Share on other sites More sharing options...
rule69 Posted May 6, 2008 Author Share Posted May 6, 2008 94770 itried that b4 didnt work... thanks: rhodesa that fixed it .. Link to comment https://forums.phpfreaks.com/topic/104434-solved-loops-not-working/#findComment-534612 Share on other sites More sharing options...
nafetski Posted May 6, 2008 Share Posted May 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/104434-solved-loops-not-working/#findComment-534705 Share on other sites More sharing options...
rule69 Posted May 6, 2008 Author Share Posted May 6, 2008 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 />"; } ?> Link to comment https://forums.phpfreaks.com/topic/104434-solved-loops-not-working/#findComment-534745 Share on other sites More sharing options...
947740 Posted May 7, 2008 Share Posted May 7, 2008 I probably should have given an example to clarify... Link to comment https://forums.phpfreaks.com/topic/104434-solved-loops-not-working/#findComment-535171 Share on other sites More sharing options...
rule69 Posted May 7, 2008 Author Share Posted May 7, 2008 Yeh thank for your help anyways... Link to comment https://forums.phpfreaks.com/topic/104434-solved-loops-not-working/#findComment-535234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.