like the title says, getting a "Query was empty" error message, this is a section of code that i am trying to use for a search facility on my site.
<?
if ($action=='keywordsearch')
{//if action
$sql = "SELECT * FROM products WHERE UPPER(CONCAT(`productid` , `brand` , `code` , `printer` , `rrp` , `price` , `availability` , `status` , `type` , `productsort` , `category` , `view` )) LIKE UPPER('%$keysearchstr%') LIMIT 0, 30";
//echo $sql;
echo '<br />';
$result = mysql_query($sql) or die(mysql_error());
$numResults = mysql_num_rows($result);
if($numresults == 0)
{
$i = (strlen($keysearchstr) - 1);//checks str length and takes one away: for array position in substr
$newString = $keysearchstr;
$str1 = $newString{0};
$str2 = $newString{$i};
//$newkeysearchstr = $str1."%".$str2;
//echo $newkeysearchstr;
$newSql = "SELECT * FROM products WHERE UPPER(CONCAT(`productid` , `brand` , `code` , `printer` , `rrp` , `price` , `availability` , `status` , `type` , `productsort` , `category` , `view` )) LIKE UPPER ('$str1%$str2') LIMIT 0, 30";
echo $newSql;
$newresult = mysql_query($newsql) or die(mysql_error());
$newnumResults = mysql_num_rows($result);
}
else if(($numResults >0)||($newnumresults >0))
{//if results >0
echo '<table border="0" class="mainBox" width="100%">';
echo '
<tr>
<td colspan="8">
Ink
</td>
</tr>
<tr>
<td align="center" width="10%">
Code
</td>
<td width="30"> </td>
<td>
Printer
</td>
<td align="center">
RRP
</td>
<td align="center">
Our Price
</td>
<td align="center">
You Save
</td>
<td align="center">
Qty
</td>
<td></td>
</tr>
';
while ($inkrow = mysql_fetch_object($result))
{//while
$productid=$inkrow->productid;
$rrp=$inkrow->rrp;
$price=$inkrow->price;
$imagename=$inkrow->type;
$image='<img src="icons/'.$imagename.'.gif" alt="'.$imagename.'" />';
$class=$inkrow->availability;
echo '<tr class="'.$class.'">';
?>
<td>
<? echo $inkrow->code; ?>
</td>
<td align="center">
<? echo $image; ?>
</td>
<td>
<? echo $inkrow->printer; ?>
</td>
<td align="center">
<? echo $rrp; ?>
</td>
<td align="center">
<? echo $price; ?>
</td>
<td align="center">
<?
$portion=($price/$rrp);
$percentage=round((100*(1-$portion)), 1);
echo ''.$percentage.'%<br />';
?>
</td>
<td align="center">
<?
if ($class=='out') {
echo '<a href="outofstock.php" title="Out of Stock. Click for more info">*</a>';
}
else {
echo '<a href="basket.php?action=add&id='.$productid.'">add</a>';
}
?>
</td>
</tr>
<?
}//while
echo '</table>';
}//if results>0
}//close if action
Database is connecting, everything working until the second sql call, when i comment out this code the search runs, not that accurate but it works, when i add second sql call gives the error message.
Any ideas please?