User Specified Order of DB Entries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GodOfHonk
Forum Newbie
Posts: 6
Joined: Thu May 09, 2002 2:17 pm
Location: St. Louis

User Specified Order of DB Entries

Post 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
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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";
}
Post Reply