galley display details page

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
mallen
Forum Newbie
Posts: 9
Joined: Thu Sep 20, 2007 9:23 pm

galley display details page

Post by mallen »

I have this dynamic gallery. It created a table of images. When I click on the image it take it to a detail page and shows the image. I can't get it to display the description. It always displays the first record's decription no matter the image that is showing. It does show the correct image. This is the gallery page:

Code: Select all

 
<?php 
define('COLS', 3);
$conn = dbConnect('query');
 
$sql = 'SELECT * FROM images';
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
 
 
 
$pictureid = $_GET['ID'];
$desc = $row['description'];
?>
 
 
 <table>
    <tr>
          <?php 
        // initialize cell counter outside loop
        $pos = 0;
        do {
        //// set caption if thumbnail is same as main image
        if ($row['description'] == $row['description']) {
        $desc = $row['description'];
        }
    
        ?>
                
    <td><p><a href="detail.php?ID=<?php echo $row['ID']; ?>"><img src="images/thumbnails/<?php echo $row['file_name']; ?>"  /></a></p></td>
    
 
  
 
        <?php
        
        // increment counter after next row extracted
        $pos++;
        // if at end of row and records remain, insert tags
        if ($pos%COLS === 0 && is_array($row)) {
        echo '</tr></tr>';
        }
        }while($row = mysql_fetch_assoc($result));  // end of loop  
        // new loop to fill in final row
        while ($pos%COLS) {
        echo '<td>&nbsp;</td>';
        $pos++;
        }
    
        ?>
</tr>
   
</table>
 
 
 
This is the detail page:

Code: Select all

 
<?php
define('COLS', 3);
$conn = dbConnect('query');
 
$sql = 'SELECT * FROM images';
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
 
$pictureid = $_GET['ID'];
 
//$desc = $_GET['description'];
$desc = $row['description'];
$link = $row['url'];
 
 
<img src="images/fullsize/<?php echo $pictureid; ?><?php echo '.jpg' ?>"  /> 
    <?php echo $desc; ?> <?php echo $link; ?>
 
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: galley display details page

Post by susrisha »

You need to change your query depending upon the picture id to get the details.
The previous query gives you the first row of the result every time

Code: Select all

 
<?php
 
define('COLS', 3);
$conn = dbConnect('query');
$pictureid = $_GET['ID'];
$sql = "SELECT * FROM images WHERE ID='$pictureid' ";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
 
 
 
//$desc = $_GET['description'];
$desc = $row['description'];
$link = $row['url'];
 
 ?>
<img src="images/fullsize/<?php echo $pictureid; ?><?php echo '.jpg' ?>"  />
    <?php echo $desc; ?> <?php echo $link; 
?>
 
Post Reply