Home  >  Article  >  Backend Development  >  多重条件组合查询(二)_PHP教程

多重条件组合查询(二)_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:31:38829browse

接一来这部分是实现用户提交之后的查询结果,也是程序代码的主体部份:  
  
$linkstr=MySQL(和PHP搭配之最佳组合)_connect("localhost","root","sa");  
MySQL(和PHP搭配之最佳组合)_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$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$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$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$showstr.="类型为".$type."并且价格少于50元的所有数据";  
break;  
case 2:  
$querystring.=" where type="".$type."" and price between 50 and 200";  
$showstr.="类型为".$type."并且价格介于50到200元间的所有数据";  
break;  

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/508962.htmlTechArticle接一来这部分是实现用户提交之后的查询结果,也是程序代码的主体部份: ? linkstr=MySQL (和PHP搭配之最佳组合) _connect("localhost","root","sa"); MySQ...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn