trymbill
11-28-2007, 06:35 PM
Hi every one!
I've got a little bit of a problem. I have a page where users can search for women in a directory I have. They should be able to type in a firstname, lastname, country, jobtitle, jobtype and some other things. Each item (firstname, lastname etc.) has it's own input field. As for now I have a LARGE if-elseif-else script that checks if there was something written for each and every column and then checks mysql with a mysql_query.
Example:
if($_POST[firstname] != '' and $_POST[lastname] == '' and $_POST[country] == '' and $_POST[jobtitle] == '' and $_POST[jobtype] == '') {
$query = mysql_query("select * from users where firstname LIKE '%$_POST[firstname]%' and active='1' and email_verified='1' order by firstname");
} elseif($_POST[firstname] == '' and $_POST[lastname] != '' and $_POST[country] == '' and $_POST[jobtitle] == '' and $_POST[jobtype] == '') {
$query = mysql_query("select * from users where lastname LIKE '%$_POST[lastname]%' and active='1' and email_verified='1' order by firstname");
} elseif($_POST[firstname] != '' and $_POST[lastname] != '' and $_POST[country] == '' and $_POST[jobtitle] == '' and $_POST[jobtype] == '') {
$query = mysql_query("select * from users where firstname LIKE '%$_POST[firstname]%' and lastname LIKE '%$_POST[lastname]%' and active='1' and email_verified='1' order by firstname");
}
My question is: How can I put this all into a small function or a small mysql_query? I can't just search for each item / column with 'LIKE' because then it displays results that have nothing in their jobtitle or lastname and it messes with every thing :confused:
If some one could help me, it would be much appreciated!
Sincerely,
Magnus
I've got a little bit of a problem. I have a page where users can search for women in a directory I have. They should be able to type in a firstname, lastname, country, jobtitle, jobtype and some other things. Each item (firstname, lastname etc.) has it's own input field. As for now I have a LARGE if-elseif-else script that checks if there was something written for each and every column and then checks mysql with a mysql_query.
Example:
if($_POST[firstname] != '' and $_POST[lastname] == '' and $_POST[country] == '' and $_POST[jobtitle] == '' and $_POST[jobtype] == '') {
$query = mysql_query("select * from users where firstname LIKE '%$_POST[firstname]%' and active='1' and email_verified='1' order by firstname");
} elseif($_POST[firstname] == '' and $_POST[lastname] != '' and $_POST[country] == '' and $_POST[jobtitle] == '' and $_POST[jobtype] == '') {
$query = mysql_query("select * from users where lastname LIKE '%$_POST[lastname]%' and active='1' and email_verified='1' order by firstname");
} elseif($_POST[firstname] != '' and $_POST[lastname] != '' and $_POST[country] == '' and $_POST[jobtitle] == '' and $_POST[jobtype] == '') {
$query = mysql_query("select * from users where firstname LIKE '%$_POST[firstname]%' and lastname LIKE '%$_POST[lastname]%' and active='1' and email_verified='1' order by firstname");
}
My question is: How can I put this all into a small function or a small mysql_query? I can't just search for each item / column with 'LIKE' because then it displays results that have nothing in their jobtitle or lastname and it messes with every thing :confused:
If some one could help me, it would be much appreciated!
Sincerely,
Magnus