It is a search query with multiple WHEREs. Any ideas?You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '''%company1%'') OR (city LIKE ''%company1%'') OR (state LIKE ''
WHERE query help
Moderator: General Moderators
WHERE query help
I get an error of:
here you go.
Here it is. Thanks for your help.
**How do I make it colored coded?
Use
Code: Select all
<?php
$colname_searchRESULTS = "1";
if (isset($_POST['search'])) {
$colname_searchRESULTS = (get_magic_quotes_gpc()) ? $_POST['search'] : addslashes($_POST['search']);
}
mysql_select_db($database_content, $content);
$query_searchRESULTS = sprintf("SELECT * FROM con_company WHERE con_company.company LIKE '%%%s%%' OR con_company.city LIKE '%%%s%%' OR con_company.`state` LIKE '%%%s%%' OR con_company.zip LIKE '%%%s%%'", $colname_searchRESULTS,$colname_searchRESULTS,$colname_searchRESULTS,$colname_searchRESULTS);
$searchRESULTS = mysql_query($query_searchRESULTS, $content) or die(mysql_error());
$row_searchRESULTS = mysql_fetch_assoc($searchRESULTS);
$totalRows_searchRESULTS = mysql_num_rows($searchRESULTS);
?>Use
Code: Select all
tags. I've done it for you - markl999[/color]I prefere to use a method such as:
I'm sure you can tweak it to suite 
Code: Select all
$sqladd = array();
if(!empty($_POST['search'])){
//the columns to search
$searchCols = array(
'company', 'city', 'state', 'zip'
);
foreach($searchCols as $scol){
$sqladd[] = $scol." LIKE '%".$_POST['search']."%'";
}
$sql = 'SELECT * FROM con_company WHERE '.join(' OR ',$sqladd);
echo $sql; //test line to see all is well
$searchRESULTS = mysql_query($sql) or die(mysql_error());
}