xXMaverickXx Posted May 19, 2008 Share Posted May 19, 2008 Hey everyone, I'm new here but I figured I'd give it a shot. I'm working on a project where I have a database with entries I want to be able to search through. Right now I have 3 text fields in a form "name" "age" and "gender" I am using " if " statements to check if there is data in the field then run the query checking for that info ' WHERE name = "$name" ' then 2 more for age and gender. Obviously this then runs 3 queries that have 3 outputs. I then tried ' WHERE name = "$name" and age = "$age" and gender = "$gender" ' I've also tried ' WHERE name = "$name" or age = "$age" ' But none give the result I'm looking for. I want to be able to put a name in hit search and the results show....while leaving age and gender blank. But when I put in a name and age it checks for entries that match both. I'm sure it's something way easier then I'm thinking it is and I'm just missing the obvious but any help you guys can share it would be awesome! Link to comment https://forums.phpfreaks.com/topic/106351-multiple-search-query-question/ Share on other sites More sharing options...
craygo Posted May 19, 2008 Share Posted May 19, 2008 You can use OR instead of AND. But that is the way searches should be WHERE name='$name' OR age = '$age' Or you can build it into your form to ask the user for it. Ray Link to comment https://forums.phpfreaks.com/topic/106351-multiple-search-query-question/#findComment-545106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.