[thelist] record sorting problem

rudy r937 at interlog.com
Thu Jun 21 13:36:20 CDT 2001

> The Problem:
> I have to make the next/previous links cycle through the rows
> in the same order as on the index page...

hi john

there are two methods of sequencing database records --

  ~ an "autonumber" which reflects entry sequence
         (may not be editable)
  ~ manually, which requires extra effort
         but can be edited

> It just dawned on me that what I am probably going to want to do
> is to leave the logic alone, and just add a column to the DB that
> puts the pieces in the order I want them in...

that would be the manual method

"autonumber" does not have to be one of those "next sequential number"
things that people use for the primary key -- you could use a datetime or
timestamp field instead and declare the default to be the current time

> ...the link looks like <a href="detail.php?id=4">.

so is your id field an autonumber?  then you'd be all set, i.e. no more
work on your part, assuming you don't mind always showing the thumbnails
and pictures in either FIFO (sort by id) or LIFO (sort by id desc) sequence

> On the detail page there are links to the next and previous pieces
> in the database. Those links are derived by adding or subtracting
> 1 to/from the current id

works okay till you get gaps from deletion -- then you're cooked

instead of #currentid# + 1, use

   select min(id)    /* next */
      from pieces
        where id > #currentid#

which of course will come back empty if you're sitting on the highest

> (with a special if statement built in for the first and last records)

there are ways around this, i.e. you can do this with sql

> until there are no more oils..then next goes to the first pastel, and so

uh oh

you want to go from highest in one category to first in the next category

well, you can also do this with sql, but it's getting trickier

how do you sequence your categories?

i bet those aren't entry sequence, are they?

manual category id?


More information about the thelist mailing list