luiskid Posted July 5, 2006 Share Posted July 5, 2006 i have made a query that contains a search field and a combobox where you can select the row. the query is working if you want to search in one row, but i want to search in multimple rows!i want that if i select the case 0 to search in all the rowsswitch($field) { case "0": $WHERE="WHERE (what should i write in here?) "; break; // case "1": $WHERE="WHERE Name; break; case "2": $WHERE="WHERE OBS"; break; case "3": $WHERE="WHERE Dept"; break; } $query = "select * from DB1 ".$WHERE." LIKE '%$search%'"; $result = mysql_db_query("DB", $query); if ($result) { Quote Link to comment https://forums.phpfreaks.com/topic/13716-query-in-multiple-fields/ Share on other sites More sharing options...
mrwhale Posted July 5, 2006 Share Posted July 5, 2006 Could you explain what you mean a bit better? Quote Link to comment https://forums.phpfreaks.com/topic/13716-query-in-multiple-fields/#findComment-53236 Share on other sites More sharing options...
luiskid Posted July 5, 2006 Author Share Posted July 5, 2006 i have a table and it look like this Name | Dept | OBS .. and if i select the option numer "0" from the combobox i want to search by all the fields (Name, Dept, OBS) Quote Link to comment https://forums.phpfreaks.com/topic/13716-query-in-multiple-fields/#findComment-53239 Share on other sites More sharing options...
mrwhale Posted July 5, 2006 Share Posted July 5, 2006 This should work:[code]<?phpswitch( $field ){ case "0": $WHERE = "WHERE Name LIKE '%$search%' and OBS LIKE '%$search%' and Dept LIKE '%$search%'"; break; case "1": $WHERE = "WHERE Name LIKE '%$search%'"; break; case "2": $WHERE = "WHERE OBS LIKE '%$search%'"; break; case "3": $WHERE = "WHERE Dept LIKE '%$search%'"; break;}$query = "select * from DB1 " . $WHERE;$result = mysql_db_query( "DB", $query );?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13716-query-in-multiple-fields/#findComment-53242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.