Filtering Database results - what's the best way?
Here is my page:
http://www.housing.uwaterloo.ca/profiles/
From the drop-down on the right side, I want to be able to sort the results. I may also add some options filter by certain fields.
What would be the best way to do this? Should I create new pages for each option or should I send a different query to the database? (not even sure how do-able that is...)
andy206uk posted this at 21:18 — 2nd February 2007.
He has: 1,758 posts
Joined: Jul 2002
It's easy. Just check for the filter, if it exists then add a bit of extra code to your SQL query:
if($_POST[filter]) {
$order = "ORDER BY ". mysql_escape_string($_POST[filter]);
}
$sql = "SELECT * FROM `table` $order";
// then just connect to db like normal
Andy
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.