多重條件組合查詢(二)
更新時(shí)間:2006年10月09日 00:00:00 作者:
接一來(lái)這部分是實(shí)現(xiàn)用戶提交之后的查詢結(jié)果,也是程序代碼的主體部份:
<?
$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."所有數(shù)據(jù)";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where no=".$no." or price<50";
$showstr.="訂單為".$no."或者價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." or price between 50 and 200";
$showstr.="訂單為".$no."或者價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no." or price>200";
$showstr.="訂單為".$no."或者價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where no=".$no." and price<50";
$showstr.="訂單為".$no."并且價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." and price between 50 and 200";
$showstr.="訂單為".$no."并且價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no." and price>200";
$showstr.="訂單為".$no."并且價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
}
}
else
{
if (!empty($type))
{
switch($select2)
{
case 1:
$querystring.=" where type="".$type."" ";
$showstr.=" 類型為".$type."所有數(shù)據(jù)";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where type="".$type."" or price<50";
$showstr.="類型為".$type."或者價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where type="".$type."" or price between 50 and 200";
$showstr.="類型為".$type."或者價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where type="".$type."" or price>200";
$showstr.="類型為".$type."或者價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where type="".$type."" and price<50";
$showstr.="類型為".$type."并且價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where type="".$type."" and price between 50 and 200";
$showstr.="類型為".$type."并且價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where type="".$type."" and price>200";
$showstr.="類型為".$type."并且價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
}
}
else
{
switch($price)
{
case 1:
$querystring.=" where price<50";
$showstr.="價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where price between 50 and 200";
$showstr.="價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where price>200";
$showstr.="價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
}
}
break;
case 2:
switch($select2)
{
case 1:
$querystring.=" where no=".$no." or type="".$type.""";
$showstr.="訂單為".$no."或者類別為".$type."所有數(shù)據(jù)";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where no=".$no." or type="".$type."" or price<50 ";
$showstr.="訂單為".$no."或者類別為".$type."或者價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." or type="".$type."" or price between 50 and 200";
$showstr.="訂單為".$no."或者類別為".$type."或者價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no."or type="".$type."" or price>200";
$showstr.="訂單為".$no."或者類別為".$type."或者價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where no=".$no." or type="".$type."" and price<50 ";
$showstr.="訂單為".$no."或者類別為".$type."并且價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." or type="".$type."" and price between 50 and 200";
$showstr.="訂單為".$no."或者類別為".$type."并且價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no."or type="".$type."" and price>200";
$showstr.="訂單為".$no."或者類別為".$type."并且價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
}
break;
case 3:
switch($select2)
{
case 1:
$querystring.=" where no=".$no." and type="".$type.""";
$showstr.="訂單為".$no."并且類別為".$type."所有數(shù)據(jù)";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where no=".$no." and type="".$type."" or price<50 ";
$showstr.="訂單為".$no."并且類別為".$type."或者價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." and type="".$type."" or price between 50 and 200";
$showstr.="訂單為".$no."并且類別為".$type."或者價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no."and type="".$type."" or price>200";
$showstr.="訂單為".$no."并且類別為".$type."或者價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where no=".$no." and type="".$type."" and price<50 ";
$showstr.="訂單為".$no."并且類別為".$type."并且價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." and type="".$type."" and price between 50 and 200";
$showstr.="訂單為".$no."并且類別為".$type."并且價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no."and type="".$type."" and price>200";
$showstr.="訂單為".$no."并且類別為".$type."并且價(jià)格大于200元間的所有數(shù)據(jù)";
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>訂單編號(hào)</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>數(shù)量</td>";
echo "<td>$qty</td>";
echo "</tr>";
echo "<tr>";
echo "<td>價(jià)格</td>";
echo "<td>$price</td>";
echo "</tr>";
echo "</table>";
}
}
?>
<?
$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."所有數(shù)據(jù)";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where no=".$no." or price<50";
$showstr.="訂單為".$no."或者價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." or price between 50 and 200";
$showstr.="訂單為".$no."或者價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no." or price>200";
$showstr.="訂單為".$no."或者價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where no=".$no." and price<50";
$showstr.="訂單為".$no."并且價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." and price between 50 and 200";
$showstr.="訂單為".$no."并且價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no." and price>200";
$showstr.="訂單為".$no."并且價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
}
}
else
{
if (!empty($type))
{
switch($select2)
{
case 1:
$querystring.=" where type="".$type."" ";
$showstr.=" 類型為".$type."所有數(shù)據(jù)";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where type="".$type."" or price<50";
$showstr.="類型為".$type."或者價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where type="".$type."" or price between 50 and 200";
$showstr.="類型為".$type."或者價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where type="".$type."" or price>200";
$showstr.="類型為".$type."或者價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where type="".$type."" and price<50";
$showstr.="類型為".$type."并且價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where type="".$type."" and price between 50 and 200";
$showstr.="類型為".$type."并且價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where type="".$type."" and price>200";
$showstr.="類型為".$type."并且價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
}
}
else
{
switch($price)
{
case 1:
$querystring.=" where price<50";
$showstr.="價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where price between 50 and 200";
$showstr.="價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where price>200";
$showstr.="價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
}
}
break;
case 2:
switch($select2)
{
case 1:
$querystring.=" where no=".$no." or type="".$type.""";
$showstr.="訂單為".$no."或者類別為".$type."所有數(shù)據(jù)";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where no=".$no." or type="".$type."" or price<50 ";
$showstr.="訂單為".$no."或者類別為".$type."或者價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." or type="".$type."" or price between 50 and 200";
$showstr.="訂單為".$no."或者類別為".$type."或者價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no."or type="".$type."" or price>200";
$showstr.="訂單為".$no."或者類別為".$type."或者價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where no=".$no." or type="".$type."" and price<50 ";
$showstr.="訂單為".$no."或者類別為".$type."并且價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." or type="".$type."" and price between 50 and 200";
$showstr.="訂單為".$no."或者類別為".$type."并且價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no."or type="".$type."" and price>200";
$showstr.="訂單為".$no."或者類別為".$type."并且價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
}
break;
case 3:
switch($select2)
{
case 1:
$querystring.=" where no=".$no." and type="".$type.""";
$showstr.="訂單為".$no."并且類別為".$type."所有數(shù)據(jù)";
break;
case 2:
switch($price)
{
case 1:
$querystring.=" where no=".$no." and type="".$type."" or price<50 ";
$showstr.="訂單為".$no."并且類別為".$type."或者價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." and type="".$type."" or price between 50 and 200";
$showstr.="訂單為".$no."并且類別為".$type."或者價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no."and type="".$type."" or price>200";
$showstr.="訂單為".$no."并且類別為".$type."或者價(jià)格大于200元間的所有數(shù)據(jù)";
break;
}
break;
case 3:
switch($price)
{
case 1:
$querystring.=" where no=".$no." and type="".$type."" and price<50 ";
$showstr.="訂單為".$no."并且類別為".$type."并且價(jià)格少于50元的所有數(shù)據(jù)";
break;
case 2:
$querystring.=" where no=".$no." and type="".$type."" and price between 50 and 200";
$showstr.="訂單為".$no."并且類別為".$type."并且價(jià)格介于50到200元間的所有數(shù)據(jù)";
break;
case 3:
$querystring.=" where no=".$no."and type="".$type."" and price>200";
$showstr.="訂單為".$no."并且類別為".$type."并且價(jià)格大于200元間的所有數(shù)據(jù)";
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>訂單編號(hào)</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>數(shù)量</td>";
echo "<td>$qty</td>";
echo "</tr>";
echo "<tr>";
echo "<td>價(jià)格</td>";
echo "<td>$price</td>";
echo "</tr>";
echo "</table>";
}
}
?>
相關(guān)文章
用Zend Encode編寫(xiě)開(kāi)發(fā)PHP程序
使用PHP的人都知道,它是一個(gè)腳本編程工具,用它寫(xiě)的程序,必須以源碼的形式放置在Web服務(wù)器上,所以我們無(wú)法保護(hù)自己的源代碼。2010-02-02圖片存儲(chǔ)與瀏覽一例(Linux+Apache+PHP+MySQL)
圖片存儲(chǔ)與瀏覽一例(Linux+Apache+PHP+MySQL)...2006-10-10PHP的FTP學(xué)習(xí)(二)[轉(zhuǎn)自?shī)W索]
PHP的FTP學(xué)習(xí)(二)[轉(zhuǎn)自?shī)W索]...2006-10-10