replace ") (" with ") OR ("
Posted: Fri Feb 21, 2003 7:14 am
ok, let's try to explain what the problem is. This script build up a query based on a search form variables. In that form we have:
$baddress
$bpostcode
$bcountry
and &boolean
it is sent to the section where we will build up a mysql query:
if ( $baddress != "" && $baddress != " " ) $mbaddress = "(baddress LIKE '%$baddress%')";
if ( $bcity != "" && $bcity != " " ) $mbcity = "(bcity LIKE '%$bcity%')";
if ( $bpostcode != "" && $bpostcode != " " ) $mbpostcode = "(bpostcode LIKE '%$bpostcode%')";
if ( $bstate != "" && $bstate != " " ) $mbstate = "(bstate LIKE '%$bstate%')";
if ( $bcountry != "" ) $mbcountry = "(bcountry LIKE '%$bcountry%')";
$sqlquery = "$mbaddress $mbcity $mbpostcode $mbstate $mbcountry";
if ($boolean == "OR") $sqlquery = str_replace (') (',') OR (', $sqlquery);
if ($boolean == "AND") $sqlquery = str_replace (') (',') AND (', $sqlquery);
mysql_select_db( $dbprofiles );
$result = mysql_query("SELECT * FROM myadd WHERE ($sqlquery) ORDER BY bname ASC, ownership ASC") or error( mysql_error() );
Now, this part doesn't work:
if ($boolean == "OR") $sqlquery = str_replace (') (',') OR (', $sqlquery);
if ($boolean == "AND") $sqlquery = str_replace (') (',') AND (', $sqlquery);
Thanks for your help,
- Vincent
$baddress
$bpostcode
$bcountry
and &boolean
it is sent to the section where we will build up a mysql query:
if ( $baddress != "" && $baddress != " " ) $mbaddress = "(baddress LIKE '%$baddress%')";
if ( $bcity != "" && $bcity != " " ) $mbcity = "(bcity LIKE '%$bcity%')";
if ( $bpostcode != "" && $bpostcode != " " ) $mbpostcode = "(bpostcode LIKE '%$bpostcode%')";
if ( $bstate != "" && $bstate != " " ) $mbstate = "(bstate LIKE '%$bstate%')";
if ( $bcountry != "" ) $mbcountry = "(bcountry LIKE '%$bcountry%')";
$sqlquery = "$mbaddress $mbcity $mbpostcode $mbstate $mbcountry";
if ($boolean == "OR") $sqlquery = str_replace (') (',') OR (', $sqlquery);
if ($boolean == "AND") $sqlquery = str_replace (') (',') AND (', $sqlquery);
mysql_select_db( $dbprofiles );
$result = mysql_query("SELECT * FROM myadd WHERE ($sqlquery) ORDER BY bname ASC, ownership ASC") or error( mysql_error() );
Now, this part doesn't work:
if ($boolean == "OR") $sqlquery = str_replace (') (',') OR (', $sqlquery);
if ($boolean == "AND") $sqlquery = str_replace (') (',') AND (', $sqlquery);
Thanks for your help,
- Vincent