4 Select boxe's web search

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
Coldman
Forum Newbie
Posts: 15
Joined: Thu Sep 06, 2007 10:15 am

4 Select boxe's web search

Post by Coldman »

Hello to all,
I am developing an web application and i have some problems creating the advanced search on this aplication.
I have 4 select boxes and an submit button. All i want is to make search on database from those select boxes. So the user can select just one selct box, or he can select two, or he can select all of them i need to get those results, what ever the user select's i want thr search script to do that.
i have one solution on my mind but i dont think that's the best one.
Let say i will use if statements. For example:

if the first select box is selected query the database only with that variable, if the first and second select boxes are selected give me the query for both variables, and so one. But this way i will need to make a lot of query's because there are a lot of combination's. A least i will need to create 16 query's.

I hope someone knows what i am trying to do and will help me on this task.

regards
Coldman
Forum Newbie
Posts: 15
Joined: Thu Sep 06, 2007 10:15 am

Re: 4 Select boxe's web search

Post by Coldman »

Help please, just post here any example, sample or whatever
Coldman
Forum Newbie
Posts: 15
Joined: Thu Sep 06, 2007 10:15 am

Re: 4 Select boxe's web search

Post by Coldman »

i try this way but is not working good

Code: Select all

if (!($kategoria =="Selekto Kategorinë") ||($lloji == "Selekto Lloin") || ($vendi == "Selekto Vendin") || ($adresa == ""))
{
$q = mysql_query("SELECT * FROM `tbllajmerimi` WHERE KategoriaID = '$kategoria' LIMIT $set_limit, $limit");
}
 
elseif (($kategoria =="Selekto Kategorinë") || !($lloji == "Selekto Lloin") || ($vendi == "Selekto Vendin") || ($adresa == ""))
{
$q = mysql_query("SELECT * FROM `tbllajmerimi` WHERE lloiID = '$lloji' LIMIT $set_limit, $limit");
}
 
elseif (!($kategoria =="Selekto Kategorinë") || !($lloji == "Selekto Lloin") || ($vendi == "Selekto Vendin") || ($adresa == ""))
{
$q = mysql_query("SELECT * FROM `tbllajmerimi` WHERE KategoriaID = '$kategoria' AND lloiID = '$lloji' LIMIT $set_limit, $limit");
}
 
elseif (!($kategoria =="Selekto Kategorinë") || !($lloji == "Selekto Lloin") || !($vendi == "Selekto Vendin") || !($adresa == ""))
{
$q = mysql_query("SELECT * FROM `tbllajmerimi` WHERE KategoriaID = '$kategoria' AND lloiID = '$lloji' AND Vendi = '$vendi' AND adresaid = '$adresa' LIMIT $set_limit, $limit");
}
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: 4 Select boxe's web search

Post by aceconcepts »

Your method seems like a pretty typical method.

It's always a bit of a headache when there are so many fields that COULD be used :D
Post Reply