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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.