Jump to content

Archived

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

pte

mysql select

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

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.