当前位置: 首页 > 图文教程 > 网络编程 > PHP > 多重條件組合查詢(二)

PHP
MYSQL版本大于4.1问题 - PHPchina
怎么让用户点击一个连接后,把一个图片另存了 - PHPchina
武汉10月15日Phper聚会召集!!! - PHPchina
php如果不等待exec执行的程序创建的子进程? - PHPchina
哪位知道DISCUZ处理防SQL注入的代码是哪部分 - PHPchina
求教!我实在不知道哪里问题,在线等ing - PHPchina
怎样结束用户某一进程 - PHPchina
比对用户名密码能不能这样写? - PHPchina
求助:如何在PHP+mysql中实现数据备份? - PHPchina
大家看看这个配置对吗 - PHPchina
如何禁止require当前文件 - PHPchina
无法将回调函数放在类中? - PHPchina
村里 PHP代码高亮是怎么实现的? - PHPchina
apache安装后.服务里没有apache2这个服务! - PHPchina
请教一个小问题 - PHPchina
config.php里面是不是应该把多数参数设置为常量而不是变量? - PHPchina
请教高手一个问题 - PHPchina
如何让百度收录我的网站 ?? - PHPchina
谁能给个注入的简单语句? - PHPchina
求PHP站内搜索思路 - PHPchina

PHP 中的 多重條件組合查詢(二)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 50 ::
收藏到网摘: n/a

接一來這部分是實現用戶提交之后的查詢結果,也是程序代碼的主体部份:
<?
$linkstr=mysql_connect("localhost","root","sa");
mysql_select_db("cx",$linkstr);
$showstr="查詢條件為:";
$querystring="select no,type,name,qty,price from orders";
switch($select1)
{
case 1:
if (!empty($no))
{
switch($select2)
{
case 1:
$querystring.=" where no=".$no;
$showstr.="訂單為".$no."所有數据";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where no=".$no." or price<50";
$showstr.="訂單為".$no."或者价格少于50元的所有數据";
break;
case 2:
$querystring.=" where no=".$no." or price between 50 and 200";
$showstr.="訂單為".$no."或者价格介于50到200元間的所有數据";
break;
case 3:
$querystring.=" where no=".$no." or price>200";
$showstr.="訂單為".$no."或者价格大于200元間的所有數据";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where no=".$no." and price<50";
$showstr.="訂單為".$no."并且价格少于50元的所有數据";
break;
case 2:
$querystring.=" where no=".$no." and price between 50 and 200";
$showstr.="訂單為".$no."并且价格介于50到200元間的所有數据";
break;
case 3:
$querystring.=" where no=".$no." and price>200";
$showstr.="訂單為".$no."并且价格大于200元間的所有數据";
break;
}
break;
}
}
else
{
if (!empty($type))
{
switch($select2)
{
case 1:
$querystring.=" where type="".$type."" ";
$showstr.=" 類型為".$type."所有數据";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where type="".$type."" or price<50";
$showstr.="類型為".$type."或者价格少于50元的所有數据";
break;
case 2:
$querystring.=" where type="".$type."" or price between 50 and 200";
$showstr.="類型為".$type."或者价格介于50到200元間的所有數据";
break;
case 3:
$querystring.=" where type="".$type."" or price>200";
$showstr.="類型為".$type."或者价格大于200元間的所有數据";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where type="".$type."" and price<50";
$showstr.="類型為".$type."并且价格少于50元的所有數据";
break;
case 2:
$querystring.=" where type="".$type."" and price between 50 and 200";
$showstr.="類型為".$type."并且价格介于50到200元間的所有數据";
break;
case 3:
$querystring.=" where type="".$type."" and price>200";
$showstr.="類型為".$type."并且价格大于200元間的所有數据";
break;
}
break;
}
}
else
{
switch($price)
{
case 1:
$querystring.=" where price<50";
$showstr.="价格少于50元的所有數据";
break;
case 2:
$querystring.=" where price between 50 and 200";
$showstr.="价格介于50到200元間的所有數据";
break;
case 3:
$querystring.=" where price>200";
$showstr.="价格大于200元間的所有數据";
break;
}
}
}
break;
case 2:
switch($select2)
{
case 1:
$querystring.=" where no=".$no." or type="".$type.""";
$showstr.="訂單為".$no."或者類別為".$type."所有數据";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where no=".$no." or type="".$type."" or price<50 ";
$showstr.="訂單為".$no."或者類別為".$type."或者价格少于50元的所有數据";
break;
case 2:
$querystring.=" where no=".$no." or type="".$type."" or price between 50 and 200";
$showstr.="訂單為".$no."或者類別為".$type."或者价格介于50到200元間的所有數据";
break;
case 3:
$querystring.=" where no=".$no."or type="".$type."" or price>200";
$showstr.="訂單為".$no."或者類別為".$type."或者价格大于200元間的所有數据";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where no=".$no." or type="".$type."" and price<50 ";
$showstr.="訂單為".$no."或者類別為".$type."并且价格少于50元的所有數据";
break;
case 2:
$querystring.=" where no=".$no." or type="".$type."" and price between 50 and 200";
$showstr.="訂單為".$no."或者類別為".$type."并且价格介于50到200元間的所有數据";
break;
case 3:
$querystring.=" where no=".$no."or type="".$type."" and price>200";
$showstr.="訂單為".$no."或者類別為".$type."并且价格大于200元間的所有數据";
break;
}
break;
}
break;
case 3:
switch($select2)
{
case 1:
$querystring.=" where no=".$no." and type="".$type.""";
$showstr.="訂單為".$no."并且類別為".$type."所有數据";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where no=".$no." and type="".$type."" or price<50 ";
$showstr.="訂單為".$no."并且類別為".$type."或者价格少于50元的所有數据";
break;
case 2:
$querystring.=" where no=".$no." and type="".$type."" or price between 50 and 200";
$showstr.="訂單為".$no."并且類別為".$type."或者价格介于50到200元間的所有數据";
break;
case 3:
$querystring.=" where no=".$no."and type="".$type."" or price>200";
$showstr.="訂單為".$no."并且類別為".$type."或者价格大于200元間的所有數据";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where no=".$no." and type="".$type."" and price<50 ";
$showstr.="訂單為".$no."并且類別為".$type."并且价格少于50元的所有數据";
break;
case 2:
$querystring.=" where no=".$no." and type="".$type."" and price between 50 and 200";
$showstr.="訂單為".$no."并且類別為".$type."并且价格介于50到200元間的所有數据";
break;
case 3:
$querystring.=" where no=".$no."and type="".$type."" and price>200";
$showstr.="訂單為".$no."并且類別為".$type."并且价格大于200元間的所有數据";
break;
}
break;
}
break;
}
$result=mysql_query($querystring,$linkstr);
echo "<p>$showstr:<p>
";
if (@mysql_num_rows($result)>0)
{
while (list($no,$type,$name,$qty,$price)=mysql_fetch_row($result))
{
echo "<table align="center">";
echo "<tr>";
echo "<td>訂單編號</td>";
echo "<td>$no</td>";
echo "</tr>";
echo "<tr>";
echo "<td>類別</td>";
echo "<td>$type</td>";
echo "</tr>";
echo "<tr>";
echo "<td>配件</td>";
echo "<td>$name</td>";
echo "</tr>";
echo "<tr>";
echo "<td>數量</td>";
echo "<td>$qty</td>";
echo "</tr>";
echo "<tr>";
echo "<td>价格</td>";
echo "<td>$price</td>";
echo "</tr>";
echo "</table>";
}
}
?>