[thelist] PHP and Databases: Data retrieval in different sort order.

rudy r937 at interlog.com
Wed Jan 22 17:34:00 CST 2003


> I have a table in MySql called Clients which has a unique (and primary)
> field called, id. The table is sorted by this 'id'.

relational database tables are not sorted

you can only get a sort order by using the ORDER BY clause

okay, sue me, i'm a pedant  ;o)


> When I click on 'previous' it should take me to the
> previous record in the alphabetical list

since you are only looking for one record, you can use this query for your
"prev" link --

     select id, Lastname
       from yourtable
      where Lastname < 'Doe'
     order by Lastname descending
     limit 1

the value 'Doe' is the value that was returned to provide the information on
the page that the user is sitting on

the value of the id that is returned by the above query is made part of the
url string on the "prev" link


rudy




More information about the thelist mailing list