Jump to content

Recommended Posts

Hi!

 

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?

 

thanks,

pieter

Link to comment
https://forums.phpfreaks.com/topic/1225-mysql-select/
Share on other sites

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.com/tutorials/73/0.php

Link to comment
https://forums.phpfreaks.com/topic/1225-mysql-select/#findComment-4186
Share on other sites

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.

 

[php:1:6653e91d25]<?php

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\";

 

$list++;

 

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

?>[/php:1:6653e91d25]

Link to comment
https://forums.phpfreaks.com/topic/1225-mysql-select/#findComment-4204
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.