PHP Gallery

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
tyanque
Forum Newbie
Posts: 2
Joined: Mon Feb 16, 2009 7:53 am

PHP Gallery

Post 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.73 KiB) Viewed 52 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 52 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());
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: PHP Gallery

Post 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...
Post Reply