Page 1 of 1

User Specified Order of DB Entries

Posted: Sun Jul 28, 2002 10:57 am
by GodOfHonk
Hello,

I just wanted to get some input from others before I charge headfirst into something that someone already has a solution to.

I have a content management type of site that allows users to add entries to a DB. Lets take FAQs for example. Instead of ordering these FAQs by title or date, I want to allow the user to specify the order in which they appear. The (seemingly) most logical thing to do would be to add a field called "Rank" to the table and order by it when I pull the results. What do you folks think is the best way to create an administration system for this situation? One could simply list all the entries with a text field and make the user fill in all of them. You could go the fancy javascript route and put them in a select list with "Move Up" and "Move Down" buttons. Has anybody ever done anything like this before? Even if you haven't done anything like this before, do you have any ideas?

Thanks!

GodOfHonk

Posted: Mon Jul 29, 2002 3:36 am
by Wayne
Try building up your sql statement. Have your basic SQL and then if an order argument has been specified then add the ORDER BY clause to the sql statement.

Code: Select all

$query = "SELECT col1, col2, col3 FROM table";

if ($order) {
    $query .= " ORDER by $order";
}