Problem with search when add BETWEEN to query
Hi guys,
Hoping someone can help me with a problem I have. I'm trying to add a "product search" function to my site. It went pretty well until I add a BETWEEN clause to the query where products within MAX and MIN price be displayed. Please help. Here is my script:
if (!isset($_GET['keyword']))
{
$keyword= "%";
}
else
{
$keyword= "%".$_GET['keyword']."%";
}
$type=$_GET['type'];
$material=$_GET['material'];
$brand=$_GET['brand'];
$seller=$_GET['seller'];
if (!isset($_GET['max_price']))
{ $max_price= "%"; } else { $max_price=$_GET['max_price']; }
if (!isset($_GET['min_price']))
{ $min_price= "%"; } else { $min_price=$_GET['min_price']; }
mysql_select_db($db_name, $connection);
$query_search_results = "SELECT * FROM $tbl_name WHERE (description LIKE ('$keyword')) AND (type LIKE ('$type')) AND (material LIKE ('$material')) AND (brand LIKE ('$brand')) AND (seller LIKE ('$seller')) AND (regular_price BETWEEN ('$max_price') AND ('$min_price'))";
And, here is the form I use:
<form action="search.php" method="get" name="search">
<label>Keyword<br />
<input name="keyword" type="text" size="15" maxlength="100" />
<br /><br />
</label>
<label>Type<br />
<select name="type" size="1">
<option value="%" selected="selected"></option>
<?
$sql = "SELECT DISTINCT type FROM product ORDER BY type ";
$result = mysql_query($sql,$connection);
while ($row = mysql_fetch_assoc($result))
{
$option = $row['type'];
echo '<option value="'.$option.'">'.$option.'</option>';
}
?>
</select><br /><br />
</label>
<label>Material<br />
<select name="material" size="1">
<option value="%" selected="selected"></option>
<?
$sql = "SELECT DISTINCT material FROM product ORDER BY material ";
$result = mysql_query($sql,$connection);
while ($row = mysql_fetch_assoc($result))
{
$option = $row['material'];
echo '<option value="'.$option.'">'.$option.'</option>';
}
?>
</select><br /><br />
</label>
<label>Brand<br />
<select name="brand" size="1">
<option value="%" selected="selected"></option>
<?
$sql = "SELECT DISTINCT brand FROM product ORDER BY brand ";
$result = mysql_query($sql,$connection);
while ($row = mysql_fetch_assoc($result))
{
$option = $row['brand'];
echo '<option value="'.$option.'">'.$option.'</option>';
}
?>
</select><br /><br />
</label>
<label>Seller<br />
<select name="seller" size="1">
<option value="%" selected="selected"></option>
<?
$sql = "SELECT DISTINCT seller FROM product ORDER BY seller ";
$result = mysql_query($sql,$connection);
while ($row = mysql_fetch_assoc($result))
{
$option = $row['seller'];
echo '<option value="'.$option.'">'.$option.'</option>';
}
?>
</select><br /><br />
</label>
<label>Maximum Price<br />
<input name="max_price" type="text" size="15" maxlength="20" />
<br /><br />
</label>
<label>Minimum price<br />
<input name="min_price" type="text" size="15" maxlength="20" />
<br /><br />
</label>
<input name="submit" type="submit" value="GO"/><br />
</form>
Subject
Written By
Posted
Problem with search when add BETWEEN to query
April 18, 2010 02:48AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.