Page 1 of 1

Filtering plez help

Posted: Fri Jan 09, 2004 1:46 pm
by grudz
Hey,

I've searched the website for my question, but i havent found anything. Here's is my situation and i am a newbie so take it easy on me:

I have two pages (list.php AND list_name.php) list.php filters all my records according to what the user clicks on another page (if they click "food", then in list.php, all the records with "food" will show, and so on). Now list_name.php is when they click on a link in list.php that says "sort in alphabetical order".
My problem is this lets say i have more links in list.php, i dont want to have to create more pages to display the information. For example if i want to sort in descending order, i have to create list_namedescending.php, then on that page, code it so that it shows the selected records in descending order. how can i code it so that list.php is the main page. i was thinking something like this

Code: Select all

WHERE alpha = 'colalpha' OR WHERE desc = 'coldesc'
can i use the OR like that?

thank you in advance

Posted: Fri Jan 09, 2004 6:09 pm
by Weirdan
just

Code: Select all

WHERE alpha = 'colalpha' OR desc = 'coldesc'

Posted: Fri Jan 09, 2004 8:22 pm
by Fataqui
Hi


To me using switch() would be great here, because you can create many different query inserts, based on many different user selectable options! Believe me, the more sorting options you give the user will tell them you put great care to cover all the angle's!


example for sorting...
[syntax=php]<?

switch ( $sort ) {
case '':
$sort = "fname ASC";
break;
case 'fname1':
$sort = "fname ASC";
break;
case 'fname2':
$sort = "fname DESC";
break;
case 'email1':
$sort = "email ASC";
break;
case 'email2':
$sort = "email DESC";
break;
case 'nicky1':
$sort = "nick ASC";
break;
case 'nicky2':
$sort = "nick DESC";
break;
}

if ( empty ( $show ) )
{
$show = 10;
}
if ( empty ( $start ) )
{
$start = 1;
}
$sql = "SELECT * FROM addbook WHERE add_name = '" . $file . "' AND add_user = '" . $user . "' ORDER BY " . $sort . " LIMIT " . $start . ", " . $show;

?>[/syntax]

My example only is for sorting, but you can create a function to do what you are wanting based on the query sent and selected by the user!


F!