Jump to content

the next or previous valid sql value


Zeradin

Recommended Posts

<?php
$image_query=mysql_query("SELECT id FROM images ORDER BY id DESC");
if($_GET['id'] > "1"){
$id=mysql_real_escape_string($_GET['id]);
$max=mysql_num_rows($image_query);   /////////NumberOfImages
$back=$id-1;   //////////BackID
if($id < $max){
$next=$id+1;   //////////NextID
}else{
$id="1";
}
$cur_img=mysql_fetch_array(mysql_query("SELECT src FROM images WHERE id='$id'"));
echo"<img src=\"".$cur_img[src]."\"><br>";
if($back){ echo"<a href=\"book.php?id=".$back."\">Back</a>"; }
if($next){ echo"<a href=\"book.php?id=".$next"\">Next</a>"; }
?>

try that , make a table with id and src then insert 1 row per image and src is the URL to the image ;)

Link to comment
Share on other sites

  • 2 weeks later...

I'm using these

   $newidquery = "SELECT id FROM yearbook WHERE id < $id AND year = 2009 AND visible = 0 ORDER BY id DESC LIMIT 1";
   $newidquery2 = "SELECT id FROM yearbook WHERE id > $id AND year = 2009 AND visible = 0 ORDER BY id ASC LIMIT 1";

 

but now I want to get the next and prev values for alphabetical order from the name column. How would I do that?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.