Jump to content

[SOLVED] Endless while loop


shatteredcode

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/109092-solved-endless-while-loop/
Share on other sites

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>"); 
}

 

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.