pte Posted October 26, 2003 Share Posted October 26, 2003 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 Quote Link to comment https://forums.phpfreaks.com/topic/1225-mysql-select/ Share on other sites More sharing options...
GeoffOs Posted October 30, 2003 Share Posted October 30, 2003 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 Quote Link to comment https://forums.phpfreaks.com/topic/1225-mysql-select/#findComment-4186 Share on other sites More sharing options...
XSpikeX Posted October 31, 2003 Share Posted October 31, 2003 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] Quote Link to comment https://forums.phpfreaks.com/topic/1225-mysql-select/#findComment-4204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.