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) { 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? 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) 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] Link to comment https://forums.phpfreaks.com/topic/13716-query-in-multiple-fields/#findComment-53242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.