SoFunction
Updated on 2025-04-09

Multiple condition combination query (I)

Usually, when we develop the system, we will not lack the query criteria? However, often the calculation conditions cannot meet the user's requirements. At this time, we should set up multiple conditions to combine them so that users can choose query conditions more conveniently and quickly find the records they meet.
Now we are suppose that we have developed a customer order system for the company, which has customer order number, category, name, quantity, price and other information. The information will not be clicked one by one here. The order table is as follows:
Order number (ID) Category (TYPE) Name (NAME) Quantity (QTY) Price (PRICE)
001 Movement Movement 1 100 150
001 Shell Shell Shell 1 1000 60
001 Table belt Table belt 1 500 70
002 Movement Movement 2 200 40
002 Shell Shell Shell 2 300 53
002 table belt Table belt 2 400 46
Now we want to build a query system so that users can edit their orders, or they can also perform quick query based on categories, prices, or their respective combinations. The number is as follows:
This section below is a form that displays query conditions

<html>  
<?  
$linkstr=mysql_connect("localhost","root","sa");  
mysql_select_db("cx",$linkstr);  
?>  
<script language="JavaScript">  
function variable()  
{  
if (.!="1")  
{  
if (=="")  
{  
("Please enter the order number!");
return false;  
}  
else  
{  
if (=="")  
{  
("Please select the accessory category!");
return false;  
}  
}  
}  
else  
{  
if (.!="1")  
{  
if (=="")  
{  
("Please enter the price!");
return false;  
}  
}  
}  
}  
</script>  
<br>  
<center><font size="5"><b>Multiple condition combination query</b></font></center>
<br>  
<body>  
<form action="" method="POST" name="search" onsubmit="return variable()">  
<table align="center" border="1" width="400">  
<tr>  
<td align="left" width="100">Order number</td>
<td align="left" width="300"><input type="text" name="no"></td>  
</tr>  
<tr>  
<td align="left" width="200">  
<select name="select1">  
<option selected value="1">  
<option value="2">or
<option value="3">and
</select>Category is
</td>  
<td align="left" width="200">  
<select name="type">  
<option selected>  
<?  
$querystring="select distinct type from orders ";  
$result=mysql_query($querystring,$linkstr);  
while (list($type)=mysql_fetch_row($result))  
{  
echo "<option value="$type">".$type;  
}  
?>  
</select>  
</tr>  
<tr>  
<td>  
<select name="select2">  
<option selected value="1">  
<option value="2">or
<option value="3">and
</select>The price is at
</td>  
<td><select name="price">  
<option selected>  
<option value="1">below 50
<option value="2">50~200?  
<option value="3">200 or above
</select> accessories
</td>  
</tr>  
<table width="400" align="right">  
<tr>  
<td>  
<input type="submit" name="submit" value="Start query">
</td>  
</tr>  
</table>  
</table>  
</form>  
</body>  
</html>