Page 1 of 1

PHP Gallery

Posted: Mon Feb 16, 2009 7:30 pm
by tyanque
Hey, Im making a gallery which gets file paths from a database and loads images depending on the PhotoAlbum row by getting the value from the URL, all of that works fine, the problem I have is showing the images in the correct way. I want there to be 3 images per row, each different, but at the moment it is showing 3 of the same image per row on 3 rows (See Attached File
Gallery
Gallery
Gallery.jpg (222.72 KiB) Viewed 54 times
, I have also attached how it looks in Dreamweaver
Screenshot of view in Dreamweaver
Screenshot of view in Dreamweaver
dreamweaver.jpg (231.62 KiB) Viewed 54 times
)
Here is the code for 1 row:

Code: Select all

<?php do { ?><tr>
                <td width="161" height="136" bgcolor="#b3b3b3"><div align="center"><a href="..<?php echo $row_images['photoFilePath']; ?><?php echo $row_images['PhotoAlbum']; ?>/<?php echo $row_images['photoName']; ?>.jpg" rel="lightbox"><img src="..<?php echo $row_images['photoFilePath']; ?><?php echo $row_images['PhotoAlbum']; ?>/<?php echo $row_images['photoName']; ?>.jpg" width="130" height="87" /></a></div></td>
                <td width="161" bgcolor="#b3b3b3"><div align="center"><a href="..<?php echo $row_images['photoFilePath']; ?><?php echo $row_images['PhotoAlbum']; ?>/<?php echo $row_images['photoName']; ?>.jpg" rel="lightbox"><img src="..<?php echo $row_images['photoFilePath']; ?><?php echo $row_images['PhotoAlbum']; ?>/<?php echo $row_images['photoName']; ?>.jpg" alt="" width="130" height="87" /></a></div></td>
                <td width="161" bgcolor="#b3b3b3"><div align="center"><a href="..<?php echo $row_images['photoFilePath']; ?><?php echo $row_images['PhotoAlbum']; ?>/<?php echo $row_images['photoName']; ?>.jpg" rel="lightbox"><img src="..<?php echo $row_images['photoFilePath']; ?><?php echo $row_images['PhotoAlbum']; ?>/<?php echo $row_images['photoName']; ?>.jpg" alt="" width="130" height="87" /></a></div></td>
              </tr><?php } while ($row_images = mysql_fetch_assoc($images)); ?>
I've Shortened it to 1 row because there is an awful lot of repetition.

$images code:

Code: Select all

mysql_select_db($database_localhost, $localhost);
$query_images = "SELECT * FROM images WHERE (PhotoAlbum ='{$colname_get}')";
$query_limit_images = sprintf("%s LIMIT %d, %d", $query_images, $startRow_images, $maxRows_images);
$images = mysql_query($query_limit_images, $localhost) or die(mysql_error());

Re: PHP Gallery

Posted: Mon Feb 16, 2009 7:50 pm
by Bill H
It looks like you are fetching from the recordset after the row is displayed?

You are doing the fetch once per row, and you need to be doing it once per column; that is three times per row.

Edit: Oh wait, I'll bet you do an initial fetch before the loop starts. Better practice would be to not do the initial fetch,
start the loop,
fetch, column, fetch, column, fetch, column
end loop

So how do you break out of it? Well there are a number of ways. Make the outer loop just a do loop ( i.e. while (1)) and then do each of the fetches as if !fetch() break; type thing, would be one quickly off the top of my head. There are probably better ways...