beaner_06 Posted March 5, 2010 Share Posted March 5, 2010 I want to perform a search that gets the value of two fields in a database when: is_wholesale=1 AND bt.bill_state LIKE '%{$search}%' I have a database named: accounts My search queries right now look like: if ($search) { $order_crit .= " AND (o.order_id LIKE '%{$search}' "; $order_crit .= "OR acct.acct_first LIKE '%{$search}%' "; $order_crit .= "OR acct.acct_last LIKE '%{$search}%' "; $order_crit .= "OR acct.acct_company LIKE '%{$search}%' "; $order_crit .= "OR acct.acct_email LIKE '{$search}%' "; $order_crit .= "OR bt.bill_country LIKE '%{$search}%' "; $order_crit .= "OR bt.bill_zip LIKE '%{$search}%' "; $order_crit .= "OR bt.bill_city LIKE '%{$search}%' "; $order_crit .= "OR bt.bill_state LIKE '%{$search}%' "; $order_crit .= "OR bt.bill_phone LIKE '%{$search}%') "; } Could I add something like this to the search query for what I am wanting to do: $order_crit .= "OR SELECT * WHERE is_wholesale = '1' AND bt.bill_state LIKE '%{$search}%' "; Or am I going to have to create a completely new function like: function get????($????) { $return = false; $sql = "SELECT * FROM accounts WHERE is_wholesale = '1' AND bt.bill_state LIKE '%{$search}%' "; if ($query = mysql_query($sql)) { $arrReturn = array(); while ($row = mysql_fetch_object($query)) { $arrReturn[] = $row; } if (!empty($arrReturn)) { $return = $arrReturn; } } return($return); } Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/194261-searching-phpsql-beginner-question/ Share on other sites More sharing options...
taquitosensei Posted March 5, 2010 Share Posted March 5, 2010 to modify yours if ($search) { $order_crit .= " AND (o.order_id LIKE '%{$search}' "; $order_crit .= "OR acct.acct_first LIKE '%{$search}%' "; $order_crit .= "OR acct.acct_last LIKE '%{$search}%' "; $order_crit .= "OR acct.acct_company LIKE '%{$search}%' "; $order_crit .= "OR acct.acct_email LIKE '{$search}%' "; $order_crit .= "OR bt.bill_country LIKE '%{$search}%' "; $order_crit .= "OR bt.bill_zip LIKE '%{$search}%' "; $order_crit .= "OR bt.bill_city LIKE '%{$search}%' "; $order_crit .= "OR bt.bill_state LIKE '%{$search}%' "; $order_crit .= "OR bt.bill_phone LIKE '%{$search}%') $order_crit.=" OR (is_wholesale=1 and bt.bill_state LIKE '%{$search}%') "; } Link to comment https://forums.phpfreaks.com/topic/194261-searching-phpsql-beginner-question/#findComment-1021973 Share on other sites More sharing options...
beaner_06 Posted March 5, 2010 Author Share Posted March 5, 2010 Is there anyway when searching to differentiate between wholesale=1 and retail=0. If a user searches with this criteria, there isn't really a way to know whether or not they are just searching for wholesale in a specified state correct? Link to comment https://forums.phpfreaks.com/topic/194261-searching-phpsql-beginner-question/#findComment-1021974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.