首页 > 开发 > PHP > 正文

多重條件組合查詢(二)

2024-05-04 22:15:58
字体:
来源:转载
供稿:网友
接一來這部分是實現用戶提交之后的查詢結果,也是程序代碼的主体部份:  
<?  
$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元的所有數据";  
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表