shatteredcode Posted June 7, 2008 Share Posted June 7, 2008 Alright, I accept that I cannot solve this. I'm doing something in this code to make a REALLY big loop. It crashes my browser. Could you tell me my error? Thanks in advance. function get_posts($table_name,$num_of_posts) { $query = "SELECT * from $table_name LIMIT $num_of_posts"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } echo ('<div id = "blog">'); while ($result <= $num_of_posts) { $row = mysql_fetch_row($result); echo ('<div id = "blog_title">'); echo ($row[1] . "<br />"); echo ('<div id = "blog_date">'); echo ($row[2] . "<br />"); echo ('<div id = "blog_tags">'); echo ($row[3] . "<br />"); echo ('<div id = "blog_post">'); echo ($row[4] . "<br />"); } echo ("</div>"); } I'm sure it's a stupid mistake. Thanks in advance. -Rick Quote Link to comment https://forums.phpfreaks.com/topic/109092-solved-endless-while-loop/ Share on other sites More sharing options...
sasa Posted June 7, 2008 Share Posted June 7, 2008 TRY function get_posts($table_name,$num_of_posts) { $query = "SELECT * from $table_name LIMIT $num_of_posts"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } echo ('<div id = "blog">'); while ($row = mysql_fetch_row($result)) { //$row = mysql_fetch_row($result); echo ('<div id = "blog_title">'); echo ($row[1] . "<br />"); echo ('<div id = "blog_date">'); echo ($row[2] . "<br />"); echo ('<div id = "blog_tags">'); echo ($row[3] . "<br />"); echo ('<div id = "blog_post">'); echo ($row[4] . "<br />"); } echo ("</div>"); } Quote Link to comment https://forums.phpfreaks.com/topic/109092-solved-endless-while-loop/#findComment-559637 Share on other sites More sharing options...
shatteredcode Posted June 7, 2008 Author Share Posted June 7, 2008 That worked perfectly! Thank you so much! Now here's the question: Why did that work? Is it because I was declaring the variable each time before, creating an endless loop? Quote Link to comment https://forums.phpfreaks.com/topic/109092-solved-endless-while-loop/#findComment-559648 Share on other sites More sharing options...
sasa Posted June 7, 2008 Share Posted June 7, 2008 in line while ($result <= $num_of_posts) you compre object with number. How coud be work Quote Link to comment https://forums.phpfreaks.com/topic/109092-solved-endless-while-loop/#findComment-559651 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.