Page 1 of 1

Working script no longer works after no changes

Posted: Wed Nov 15, 2006 10:51 pm
by waradmin
Alright so once the $row_count value on this script was higher than 4 (currently its 5) the page no longer loads, but says it is loading and after that seems to slow down the entire webserver (my host is going to kill me).

Here is the code, its supposed to list 4 images per row, then go to the next row if there are more than 4 images and display the rest of the images.

Code: Select all

<?php
include('functions.php');
$i = 0;
while($i < $num_rows) {
	$row = mysql_fetch_array( $result );
    if($i == 4){
        $i = 0;
        echo "</tr>";
    }
    if($i == 0) {
        echo "<tr>";
	}
	if($i <= 4) {
		$picture = $row['photo_url'];
		list($w, $h) = getimagesize($picture);
		if($w > 130) {
		$scale = imageScale($picture, 130, -1);
		$width = $scale[0];
		$height = $scale[1];
    	echo "<td onMouseOver=\"style.backgroundColor='#3b5998';\" onMouseOut=\"style.backgroundColor='#FFFFFF'\"><a href=\"viewphoto.php?album=" . $row['album_id'] . "&photo=" . $row['id'] . "&id=" . $row['global_id'] . "\"><img src=\"$picture\" width=\"$width\" height=\"$height\"></a></td>";
		}
		else
		{
		echo "<td onMouseOver=\"style.backgroundColor='#3b5998';\" onMouseOut=\"style.backgroundColor='#FFFFFF'\"><a href=\"viewphoto.php?album=" . $row['album_id'] . "&photo=" . $row['id'] . "&id=" . $row['global_id'] . "\"><img src=\"$picture\"></a></td>";
		}
    	$i++;
	}
}
?>

Posted: Wed Nov 15, 2006 11:01 pm
by feyd
I don't see $num_rows being set anywhere.

The first two threads linked from Useful Posts may be of interest/use.

Posted: Wed Nov 15, 2006 11:04 pm
by waradmin
Ive looked at the posts, here is the full code showing num rows. The address I am trying to link to is similar to photos.php?album=NO&id=7676666

Code: Select all

<?php
if($_GET['album'] == "NO")
{
	$result = mysql_query("SELECT * FROM photos WHERE global_id='{$_GET[id]}' ORDER BY id desc") or die(mysql_error());
	$num_rows = mysql_num_rows( $result );
?><center><table cellpadding="6">
<?php
include('functions.php');
$i = 0;
while($i < $num_rows) {
	$row = mysql_fetch_array( $result );
    if($i == 4){
        $i = 0;
        echo "</tr>";
    }
    if($i == 0) {
        echo "<tr>";
	}
	if($i <= 4) {
		$picture = $row['photo_url'];
		list($w, $h) = getimagesize($picture);
		if($w > 130) {
		$scale = imageScale($picture, 130, -1);
		$width = $scale[0];
		$height = $scale[1];
    	echo "<td onMouseOver=\"style.backgroundColor='#3b5998';\" onMouseOut=\"style.backgroundColor='#FFFFFF'\"><a href=\"viewphoto.php?album=" . $row['album_id'] . "&photo=" . $row['id'] . "&id=" . $row['global_id'] . "\"><img src=\"$picture\" width=\"$width\" height=\"$height\"></a></td>";
		}
		else
		{
		echo "<td onMouseOver=\"style.backgroundColor='#3b5998';\" onMouseOut=\"style.backgroundColor='#FFFFFF'\"><a href=\"viewphoto.php?album=" . $row['album_id'] . "&photo=" . $row['id'] . "&id=" . $row['global_id'] . "\"><img src=\"$picture\"></a></td>";
		}
    	$i++;
	}
}
?>
</table></center>
<?php
}
else
{
	$result = mysql_query("SELECT * FROM photos WHERE global_id='".$_GET[id]."' AND album_id='".$_GET[album]."' ORDER BY id desc") or die(mysql_error());
	$num_rows = mysql_num_rows( $result );
?><center><table cellpadding="6">
<?php
include('functions.php');
$i = 0;
while($i < $num_rows) {
	$row = mysql_fetch_array( $result );
    if($i ==4){
        $i=0;
        echo "</tr>";
    }
    if($i ==0) {
        echo "<tr>";
	}
	if($i <= 4) {
		$picture = $row['photo_url'];
		list($w, $h) = getimagesize($picture);
		if($w > 130) {
		$scale = imageScale($picture, 130, -1);
		$width = $scale[0];
		$height = $scale[1];
    	echo "<td onMouseOver=\"style.backgroundColor='#3b5998';\" onMouseOut=\"style.backgroundColor='#FFFFFF'\"><a href=\"viewphoto.php?album=" . $row['album_id'] . "&photo=" . $row['id'] . "&id=" . $row['global_id'] . "\"><img src=\"$picture\" width=\"$width\" height=\"$height\"></a></td>";
		}
		else
		{
		echo "<td onMouseOver=\"style.backgroundColor='#3b5998';\" onMouseOut=\"style.backgroundColor='#FFFFFF'\"><a href=\"viewphoto.php?album=" . $row['album_id'] . "&photo=" . $row['id'] . "&id=" . $row['global_id'] . "\"><img src=\"$picture\"></a></td>";
		}
    	$i++;
	}
}
?>