I have users that can have images on my site. On their profile page you can click on a link that brings up a pop up with one of the user's images and two links. PREVIOUS and NEXT
I want them to be able to page through the user's images using the PREVIOUS and NEXT buttons.
Whats the best way to handle that?
I was thinking you'd have to create a session array with the user's img ids. Anyone do this before?
thanks all!
How would you guys do this? Sorting through an array...
Moderator: General Moderators
You could like do something like:
of course connecting to your database before that....
Code: Select all
<?php
$result = mysql_query("SELECT * FROM user_table WHERE id = '$id'");
while ($fetch = mysql_fetch_assoc($result)) {
echo "<img src=$fetch[image]>";
}
echo "<a href=?id=" . ($id-1) . ">Previous</a>-<a href=?id=" . ($id+1) . ">Next</a>";
?>-
pootergeist
- Forum Contributor
- Posts: 273
- Joined: Thu Feb 27, 2003 7:22 am
- Location: UK
yup - I'd build an array of image_ids based on a query where the user=user_id
then run $_SESSION['name'] = serialize($the_array);
some basic isset logic should make sure the query only runs the first page view - then just unserialize to a base variable and determine next-previous to mimic the array key
$img_array = unserialize($_SESSION['name']);
echo '<img src="' .$img_array[($_GET['ref'])]. '" />';
determine if $_GET['ref'] is zero or count($img_array)-1 and output next/previous
then run $_SESSION['name'] = serialize($the_array);
some basic isset logic should make sure the query only runs the first page view - then just unserialize to a base variable and determine next-previous to mimic the array key
$img_array = unserialize($_SESSION['name']);
echo '<img src="' .$img_array[($_GET['ref'])]. '" />';
determine if $_GET['ref'] is zero or count($img_array)-1 and output next/previous