Page 1 of 1

output buffering not working within the logic

Posted: Mon Apr 10, 2006 2:19 pm
by malcolmboston
i have this code

Code: Select all

$query = "SELECT * FROM rl_links";
$result = mysql_query($query) or die (mysql_error());
?>
<table width="1000" border="0" cellspacing="3" cellpadding="3">
<?
while ($array = mysql_fetch_array($result))
{
	if (!isset($i)) {
		$i = 1;
	}
	ob_start ();
	echo '                                                                                                             ';
	$std = new getURLInformation($array['url']);
	$rec = new getURLInformation($array['reciprocal']);
	// get colors to display table background
	if ($std->validURL === TRUE) {
		$tdURLBackground = "green";
	} else {
		$tdURLBackground = "red";
	}
	if ($rec->validURL === TRUE) {
		$tdRecBackground = "green";
	} else {
		$tdRecBackground = "red";
	}
	?>
	<tr>
    	<td class="num" width="74" rowspan="2"><?=$i;?></td>
    	<td class="content" width="926" style="background-color: <?=$tdURLBackground;?>"><?=$array['url'];?></td>
    </tr>
    <tr>
    	<td class="content" style="background-color: <?=$tdRecBackground;?>"><?=$array['reciprocal'];?></td>
    </tr>
    <tr>
    	<td colspan="2">&nbsp;</td>
    </tr>
	<?
	unset($std);
	unset($rec);
	ob_end_flush();
	$i++;
}
	?>
</table>
</body>
</html>
which in my eyes should do 1 loop and then print out the results to the browser, however it will maybe do 1-19 and then print out to the browser, then 20-38 etc.

Why is it doing this?

Posted: Mon Apr 10, 2006 2:23 pm
by feyd
output buffering generally causes this, but also the web server can buffer the output data.

Posted: Mon Apr 10, 2006 2:26 pm
by malcolmboston
ok, how do i get it to do what i want then? because even showing results 1-19 can take anywhere upto 60 seconds, and as it stands now, theres 179 items in the database

I understand i could use pagination but im trying to keep the code as simple as possible

Posted: Mon Apr 10, 2006 2:55 pm
by Roja
Check to make sure that your php itself isn't using output buffering (fairly common).

http://us2.php.net/manual/en/function.ob-get-level.php right at the beginning of your script.

Posted: Mon Apr 10, 2006 10:47 pm
by josh
You need ob_implicit_flush