Working script no longer works after no changes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Working script no longer works after no changes

Post 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++;
	}
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't see $num_rows being set anywhere.

The first two threads linked from Useful Posts may be of interest/use.
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Post 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++;
	}
}
?>
Post Reply