Cronthenoob Posted August 21, 2006 Share Posted August 21, 2006 I've got a loop, that I need to stop after a certain number of times through.If I use exit() then everything beyond that point doesnt load into the page. Is there another way I can stop the loop but load the rest of the page?Heres my code. <?PHP $query="SELECT * from cddb_albums order by album_id DESC"; $results=mysql_query($query); echo mysql_error(); $newalbum=1; while($e = mysql_fetch_array($results)) { if ($newalbum <= 5) { echo $e[album_title]."<br />"; $newalbum=$newalbum+1; if ($newalbum == "6") { exit(); } } } ?> Link to comment Share on other sites More sharing options...
aspnetguy Posted August 21, 2006 Share Posted August 21, 2006 php.net to the rescue http://ca.php.net/break Link to comment Share on other sites More sharing options...
ThePsion5 Posted August 21, 2006 Share Posted August 21, 2006 I'm not entirely sure, but I think you can use break; to exit from the loop, but continue execution. If that doesn't work, you can recode your loop like so: $continue = true;while($e = mysql_fetch_array($results) && $continue){ if ($newalbum <= 5) { echo $e[album_title]."<br />"; $newalbum=$newalbum+1; if ($newalbum == "6") $continue = false; }} That will have the same effect as using break; in place of the $continue=false; line. Link to comment Share on other sites More sharing options...
Cronthenoob Posted August 21, 2006 Author Share Posted August 21, 2006 Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now