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 ;)

  • 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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.