Jump to content

Searching PHP/SQL Beginner Question


beaner_06

Recommended Posts

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

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}%')
";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.