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. Quote Link to comment 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}%') "; } Quote Link to comment 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? Quote Link to comment 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.