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!
$searchword=$_GET[searchword];
$state=$_GET[state];
$type=$_GET[type];
$query = "SELECT id, name, state, address, type FROM table WHERE name='$searchword' AND state='$state' AND type='$type'";
The html form is just a textbox and two drop down menus. It works if I enter in the values but I want to have an option for each catagory to include everything in that column. Like if I entered a name and choose a type and selected an option so that it included all of the states.
Thank you,
-Rivaldi
if ($state == 'All'){
$query = "SELECT id, name, state, address, type FROM table WHERE name='$searchword' AND type='$type'";
}else{
$query = "SELECT id, name, state, address, type FROM table WHERE name='$searchword' AND state='$state' AND type='$type'";
}
Not sure if this is the most efficient solution. I'm very new to this, but it worked for me in a similar situation
It displays all the available columns, and allows the user to type values they want to search for.. After that they are redirected to the "list" script again, but the posted search values will be used to generate additional WHERE stuff
If the user decides to refine his search, he has to go back to the "search" script, where he will be able to modify the search criteria..
SELECT
id,
name,
state,
address,
type
FROM
table
WHERE
name LIKE '%$searchword%' AND
state LIKE '%$state%' AND
type LIKE '%$type%'
So when nothing is entered, $searchword and/or $state and/or $type will be blank. The query will then look for columns LIKE '%%' which will match everything.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.