|
-
May 15th, 2006, 11:02 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED]Getting the previous and next Mysql entries
I am storing paths to images in a db, what I want to do is get an image path from the db, but then also get the previous entry and next entry around the current path that I selected. I am making a photo gallery and want to display 2 thumbnails for navigation on each side of the "main" bigger picture.
Any help would be great
Last edited by zalez; May 18th, 2006 at 01:10 AM.
-
May 16th, 2006, 05:14 AM
#2
Re: Getting the previous and next Mysql entries
How are you retrieving the data? If you could post the code you are using to do that we can suggest something.
-
May 16th, 2006, 08:32 AM
#3
Re: Getting the previous and next Mysql entries
What's your concept of "previous" and "next"? The DB itself doesn't really have one - it depends on the sorting of the data.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 16th, 2006, 10:45 PM
#4
Thread Starter
Hyperactive Member
Re: Getting the previous and next Mysql entries
Basically i'll pass the photo id in the url, then I have a function that gets the id and queries the db for that id.
This is the type of url I am using:
photo.php?imageid=9
PHP Code:
function display_image() {
if(isset($_GET['imageid'])){
$imageid = $_GET['imageid'];
$result = mysql_query("SELECT * FROM photos WHERE id = '$imageid'");
$myrow = mysql_fetch_array($result);
$uid = $myrow[userid];
$imagename = $myrow[fname] . "." . $myrow[ext];
$uresult = mysql_query("SELECT * FROM users WHERE userid = '$uid'");
$umyrow = mysql_fetch_array($uresult);
$path = "/photo/upload_pic/$umyrow[username]/$imagename";
echo $path;
}
}
I would just use the photo id and subtract one or add one but im giving the user the option to delete photos so they will not always be sequencial.
-
May 17th, 2006, 03:13 AM
#5
Re: Getting the previous and next Mysql entries
PHP Code:
$imageid = intval($_GET['imageid']); // Prevent SQL injection.
// Query for the current row:
$query = "SELECT * FROM photos WHERE id = $imageid";
// For the previous:
$query = "SELECT * FROM photos WHERE id < $imageid ORDER BY id DESC LIMIT 1";
// For the next:
$query = "SELECT * FROM photos WHERE id > $imageid ORDER BY id ASC LIMIT 1";
Last edited by john tindell; May 17th, 2006 at 07:21 AM.
Reason: Fixed Tags
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 18th, 2006, 01:09 AM
#6
Thread Starter
Hyperactive Member
Re: Getting the previous and next Mysql entries
Something so simple yet so far away from my brain Thanks alot Cornedbee, it worked like a charm.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|