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
waradmin
Forum Contributor
Posts: 240 Joined: Fri Nov 04, 2005 2:57 pm
Post
by waradmin » Wed Nov 15, 2006 10:51 pm
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++;
}
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Nov 15, 2006 11:01 pm
I don't see $num_rows being set anywhere.
The first two threads linked from Useful Posts may be of interest/use.
waradmin
Forum Contributor
Posts: 240 Joined: Fri Nov 04, 2005 2:57 pm
Post
by waradmin » Wed Nov 15, 2006 11:04 pm
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++;
}
}
?>