/    Sign up×
Community /Pin to ProfileBookmark

Finding Next and Previous items…

Hi Guys, really need some help on this…it’s been kicking my ass all day!

I’m trying to create a photo browser so that when you click the Next and Prev buttons either the Next or Previous image is displayed, but i can’t seem to extract the ID’s for them. My code goes a bit like this:

[code=php]$query_image = “SELECT image_id, image_path, image_description
FROM gallery_images
WHERE group_id = $group_id”;

$results_image = mysql_query($query_image);

if ($results_image)
{

while ($row_array_image = mysql_fetch_row($results_image))
{

$fetched_image_id = $row_array_image[0];
$image_path = $row_array_image[1];
$image_description = $row_array_image[2];

if ($fetched_image_id == $image_id)
{
$image_string = ‘<tr bgcolor=”#333366″><td colspan=”3″><img src=”../’.$image_path.'” /></td></tr>’;
$nav_string = ‘<tr bgcolor=”#333366″><td><a href=”http://www.ugmfc.com/image_viewer.php?image_id=’.$prev.’&group_id=’.$group_id.'”><img src=”images/prevshot-n.gif” align=”left” /></a></td><td><div class=”description”>’.$image_description.'</div></td><td><a href=”http://www.ugmfc.com/image_viewer.php?image_id=’.$next.’&group_id=’.$group_id.'”><img src=”images/nextshot-n.gif” align=”right” /></a></td></tr>’;
}
}

echo $nav_string;
echo $image_string;
echo $nav_string;
}[/code]

As you can see in the $nav_string i have $next & $prev where the image_id should be. I’ve tried using:

[code=php]$next = mysql_result(query_image, $count);[/code]

Where $count was the current row number + 1 but it didn’t like having a variable for the row number. I’ve played with next(); & prev(); with no luck and also mysql_data_seek (but again i don’t think that liked the variable).

If you can help us out it would be much appreciated. Durbs

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@scrotayeAug 05.2005 — I think you will find this script I wrote a while back useful. It populates the $next and $previous links

Feel free to tear it apart.

[code=php]
<?
// Query for all of the filenames in this gallery
$filenamequery = mysql_query("SELECT filename FROM $data2 WHERE galleryid = '$gal' ORDER BY id ASC");

// Prepare an array for the 'filename' contents
$bob = array();

// Loop through the filenames and store them in the prepared array
while($row = mysql_fetch_assoc($filenamequery))
{
$bob[] = $row['filename'];
}

// Select the appropriate filename
$filename = $bob[$_GET['pic']-1];

$picsize = getimagesize("/home/username/public_html/members/galleries/$type/$gal/big/$filename");
if($picsize['0'] > 600)
{
?><img src="galleries/<? echo $type; ?>/<? echo $gal; ?>/big/<? echo $filename; ?>" width="600" alt="Gallery Picture"><BR>
This picture has been scaled down in size. To see the full sized picture, click on it.
<? } ELSE
{
?><img src="galleries/<? echo $type; ?>/<? echo $gal; ?>/big/<? echo $filename; ?>" alt="Gallery Picture">
<? } ?>
</td>
</tr>
<tr>
<td width="50%">
<?
// Previous button -- leave intact
if($_GET['pic'] != 1)
{
$previous = $_GET['pic']-1;
echo "<a href="gal_picpage.php?type=$type&gal=$gal&pic=$previous">Previous</a>";
} ?>
</td>
<td width="50%" align="right">
<?
// Next button -- leave intact
$numberpics = sizeof($bob);
if($_GET['pic'] != $numberpics)
{
$next = $_GET['pic']+1;
echo "<a href="gal_picpage.php?type=$type&gal=$gal&pic=$next">Next</a>";
} ?>
[/code]


The most important part you should look at is the populating of the $bob array
Copy linkTweet thisAlerts:
@DurbsauthorAug 07.2005 — Cheers buddy thats pretty much what i wanted, more than put me back on track.

Cheers, Durbs
×

Success!

Help @Durbs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...