Search using Multiple Criteria
Posted: Tue Dec 16, 2008 1:43 am
Hi
I am new here and new to PHP programing so sry if this is a noob question but i tried to make a search function in PHP using a MySQL database and i have no more idea what to do.
Let say we have a database with ID, NAME, ADDRESS, AGE and COUNTRY.
So on one page i use a form where you can put this search criteria into but you can leave them blank if you want. Now the problem is that if i use:
and someone put a field blank i wont get any result 
If i use OR instead of AND i will get results that i don't want.
Can anybody help me?
I am new here and new to PHP programing so sry if this is a noob question but i tried to make a search function in PHP using a MySQL database and i have no more idea what to do.
Let say we have a database with ID, NAME, ADDRESS, AGE and COUNTRY.
So on one page i use a form where you can put this search criteria into but you can leave them blank if you want. Now the problem is that if i use:
Code: Select all
("SELECT * FROM user
WHERE NAME='$name' AND ADDRESS='$address' AND AGE='$age' AND COUNTRY='$country'
ORDER BY ID ASC")
If i use OR instead of AND i will get results that i don't want.
Can anybody help me?