FutonGuy Posted December 18, 2009 Share Posted December 18, 2009 Hi does anyone know how to work on a combination of search queries of 2 or more different fields to narrow down the search option? Scenario: dev number: [free text-wildcard will be use] site : [option-drop down list] board number: [free text-wildcard will be use] [sEARCH BUTTON] User can search by either one of the options or all of the option to narrow down the search queries. here's the code i have. Hopefully someone can help me with my queries.. $val_d = $_POST['device_search']; $val_sub = $_POST['subconsite']; echo "$val_d"; echo "<br>"; echo "$val_sub"; if (trim($val_d) != '' or trim($val_sub) != ''){ $sql = "select * from wsdevice"; if (trim($val_d) != ''){ $sql .= " where wsdevice_num like '%$val_d%' "; //'%" . trim($val_d) . "%' $where = true; } if (trim($val_sub) != ''){ if (!$where){ $sql .= " where subcon_site like '%$val_sub%' "; // '%" . trim($val_sub) . "%' } else { $sql = str_replace("where ", "where (", $sql); $sql .= " and subcon_site like '%$val_sub%') or (wsdevice_num like '%$val_d%' or subcon_site like '%$val_sub%')"; } // '%" . trim($val_sub) . "%' '%" . trim($val_sub) . "%' '%" . trim($val_d) . "%' } else { die("NO SEARCH TERMS"); } $results = mysql_query($sql) or die (mysql_error()); $numrows = mysql_num_rows($results); // This is where i output my results include "WSsearchtable.php"; Cheers.. Link to comment https://forums.phpfreaks.com/topic/185568-combine-search-queries-into-1-search-post/ Share on other sites More sharing options...
teynon Posted December 18, 2009 Share Posted December 18, 2009 Use "OR" SELECT * FROM table WHERE sect1 like %query% OR sect2 like %query% OR sect3 like %query% Link to comment https://forums.phpfreaks.com/topic/185568-combine-search-queries-into-1-search-post/#findComment-979713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.