Jump to content


mysql select

  • Please log in to reply
2 replies to this topic

#1 pte

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 26 October 2003 - 11:12 PM


I am wondering how I can find out the index of a row in a MySql table given a certain order. For example I have a table containing information of some images on my computer. After

SELECT * FROM Images WHERE Id=\'12\' ORDER BY Date

I get an Image and want to find the next image (next in the Date order). So I would like something as

index = GETINDEX FROM Images WHERE Id=\'12\' ORDER BY Date
nextimage = SELECT * FROM Images WHERE ORDER BY Date LIMIT index+1, index+1

Someone know how to code this into a proper SQL query?


#2 GeoffOs

  • Members
  • PipPip
  • Member
  • 24 posts
  • LocationCheshire, England

Posted 30 October 2003 - 08:30 PM

Not quite sure why you would need to do what you are talking about.
Could you not iterate through the recordset you already have. You have specified a date order so the next record in the recordset would be the next record by date. If not I would do something like this
Select the record
Display the current record
Move to the next record and get an id column stored as a var

This would allow you to page through the results.

Though this should be a good tutorial for you :http://www.phpfreaks...orials/73/0.php
Beyond a critical point within a finite space, freedom diminishes as numbers increase....[br]The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."[br]-- Frank Herbert - Dune

#3 XSpikeX

  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 31 October 2003 - 03:17 PM

If think you mean you wanna only see one then have the option to see the next. This is the only thing I can think of. Of course you\'ll have to add your username/password info but this is the jist of the script.

if (!isset($list)) {
$list = 1;

$sql = \"SELECT * FROM images WHERE Id=\'12\' ORDER BY Date LIMIT $list\";
$result = MySQL_query($result);
$results = MySQL_fetch_row($result);
$info = $results[\'Info\'];

echo \"$info\";


$echo \"<br><a href=\'thisfile.php?list=$list\'>Next image\'s info</a>\";

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users