Page 1 of 1

Searching PHP/SQL Beginner Question

Posted: Fri Mar 05, 2010 9:58 am
by beaner_06
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:

Code: Select all

 
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:

Code: Select all

$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:

Code: Select all

 
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.

Re: Searching PHP/SQL Beginner Question

Posted: Fri Mar 05, 2010 10:14 am
by beaner_06
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?