Filtering plez help

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
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

Filtering plez help

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

just

Code: Select all

WHERE alpha = 'colalpha' OR desc = 'coldesc'
Fataqui
Forum Newbie
Posts: 10
Joined: Fri Jan 09, 2004 7:47 pm

Post 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!
Post Reply