Hi VGR,
Actually with ID it would have been simple, but you know that for instance, addressbook, is usually not entered in alphabatecial order. When I display records they are ordered. When I open specific entry I want to be able to navigate to next one, previous one, last one, first one (but not according to it's uniq id, but it's name). What I have to do is compare strings... if string is < then currect one or >... but this somehow doesn't give me proper results.
Since there might be large number of records I would like to avoid local storing.
Main Topics
Browse All Topics





by: VGRPosted on 2003-10-06 at 00:15:50ID: 9496712
1) well... if you memorize all the results set from your initial SELECT * FROM...
going to previous or next is a matter of incrementing the array index, and last and first are indices count($array)-1 and 0
2) if you didn't memorize the whole results set, try to memorize the returned IDs of the rows returned in it [all tables should have an "ID integer unique auto_increment"] and apply the same technique
3) if you don't want to memorize anything, then :
-given you use $sql="SELECT * FROM ... WHERE ..." to get all results,
-first record is $sql.' ORDER BY some_field ASC LIMIT 1;';
-last record is $sql.' ORDER BY some_field DESC LIMIT 1;';
-given you use $sql2="SELECT * FROM ... "." WHERE ID=$somevalue" to get the currently displayed result,
-previous record is $sql2.' WHERE ID<$somevalue ORDER BY ID DESC LIMIT 1;';
-next record is $sql2.' WHERE ID>$somevalue ORDER BY ID ASC LIMIT 1;';
regards