Combined query by multiple conditions (2) This part is the result of the query after the actual use case is submitted. it is also the main part of the program generation:
$ Linkstr = mysql_connect ("localhost", "root", "sa ");
Mysql_select_db ("cx", $ linkstr );
$ Showstr = "Check Condition :";
$ 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. = "stand alone". $ no. "all data ";
Break;
Case 2:
Switch ($ price)
{
Case 1:
$ Querystring. = "where no =". $ no. "or price <50 ";
$ Showstr. = "simply". $ no. "or all data with a price less than 50 RMB ";
Break;
Case 2:
$ Querystring. = "where no =". $ no. "or price between 50 and 200 ";
$ Showstr. = "simply". $ no. "or all data with a price ranging from 50 to 200 RMB ";
Break;
Case 3:
$ Querystring. = "where no =". $ no. "or price> 200 ";
$ Showstr. = "simply". $ no. "or all data with a price greater than 200 RMB ";
Break;
}
Break;
Case 3:
Switch ($ price)
{
Case 1:
$ Querystring. = "where no =". $ no. "and price <50 ";
$ Showstr. = "all data with a price of less than 50 RMB ";
Break;
Case 2:
$ Querystring. = "where no =". $ no. "and price between 50 and 200 ";
$ Showstr. = "billing method". $ no. "all data with a price between 50 and 200 RMB ";
Break;
Case 3:
$ Querystring. = "where no =". $ no. "and price> 200 ";
$ Showstr. = "all data with a price greater than 200 RMB ";
Break;
}
Break;
}
}
Else
{
If (! Empty ($ type ))
{
Switch ($ select2)
{
Case 1:
$ Querystring. = "where type =" ". $ type .""";
$ Showstr. = "type =". $ type. "all data ";
Break;
Case 2:
Switch ($ price)
{
Case 1:
$ Querystring. = "where type =" ". $ type." "or price <50 ";
$ Showstr. = "type:". $ type. "or all data with a price less than 50 RMB ";
Break;
Case 2:
$ Querystring. = "where type =" ". $ type." "or price between 50 and 200 ";
$ Showstr. = "type:". $ type. "or all data with a price between 50 and 200 RMB ";
Break;
Case 3:
$ Querystring. = "where type =" ". $ type." "or price> 200 ";
$ Showstr. = "type =". $ type. "or all data with a price greater than 200 RMB ";
Break;
}
Break;
Case 3:
Switch ($ price)
{
Case 1:
$ Querystring. = "where type =" ". $ type." "and price <50 ";
$ Showstr. = "all data whose type is". $ type. "and whose price is less than 50 RMB ";
Break;
Case 2:
$ Querystring. = "where type =" ". $ type." "and price between 50 and 200 ";
$ Showstr. = "type =". $ type. "all data with a price between 50 and 200 RMB ";
Break;
Case 3:
$ Querystring. = "where type =" ". $ type." "and price> 200 ";
$ Showstr. = "type =". $ type. "all data with a price greater than 200 RMB ";
Break;
}
Break;
}
}
Else
{
Switch ($ price)
{
Case 1:
$ Querystring. = "where price <50 ";
$ Showstr. = "all data whose price is less than 50 RMB ";
Break;
Case 2:
$ Querystring. = "where price between 50 & 200 ";
$ Showstr. = "all data whose prices are between 50 and 200 RMB ";
Break;
Case 3:
$ Querystring. = "where price> 200 ";
$ Showstr. = "all data whose price is greater than 200 RMB ";
Break;
}
}
}
Break;
Case 2:
Switch ($ select2)
{
Case 1:
$ Querystring. = "where no =". $ no. "or type =" ". $ type .""";
$ Showstr. = "simply". $ no. "or". $ type. "all data ";
Break;
Case 2:
Switch ($ price)
{
Case 1:
$ Querystring. = "where no =". $ no. "or type =" ". $ type." "or price <50 ";
$ Showstr. = "simply". $ no. "or". $ type. "or all data with a price less than 50 RMB ";
Break;
Case 2:
$ Querystring. = "where no =". $ no. "or type =" ". $ type." "or price between 50 and 200 ";
$ Showstr. = "simply". $ no. "or". $ type. "or all data with a price between 50 and 200 RMB ";
Break;
Case 3:
$ Querystring. = "where no =". $ no. "or type =" ". $ type." "or price> 200 ";
$ Showstr. = "simply". $ no. "or". $ type. "or all data with a price greater than 200 RMB ";
Break;
}
Break;
Case 3:
Switch ($ price)
{
Case 1:
$ Querystring. = "where no =". $ no. "or type =" ". $ type." "and price <50 ";
$ Showstr. = "billing method". $ no. "or". $ type. "for all data whose price is less than 50 RMB ";
Break;
Case 2:
$ Querystring. = "where no =". $ no. "or type =" ". $ type." "and price between 50 and 200 ";
$ Showstr. = "simply". $ no. "or". $ type. "all data with a price between 50 and 200 RMB ";
Break;
Case 3:
$ Querystring. = "where no =". $ no. "or type =" ". $ type." "and price> 200 ";
$ Showstr. = "billing method". $ no. "or". $ type. "all data with a price greater than 200 RMB ";
Break;
}
Break;
}
Break;
Case 3:
Switch ($ select2)
{
Case 1:
$ Querystring. = "where no =". $ no. "and type =" ". $ type .""";
$ Showstr. = "statement". $ no. "and". $ type. "all data ";
Break;
Case 2:
Switch ($ price)
{
Case 1:
$ Querystring. = "where no =". $ no. "and type =" ". $ type." "or price <50 ";
$ Showstr. = "statement". $ no. "and". $ type. "or all data with a price less than 50 RMB ";
Break;
Case 2:
$ Querystring. = "where no =". $ no. "and type =" ". $ type." "or price between 50 and 200 ";
$ Showstr. = "statement". $ no. "and". $ type. "or all data with a price between 50 and 200 RMB ";
Break;
Case 3:
$ Querystring. = "where no =". $ no. "and type =" ". $ type." "or price> 200 ";
$ Showstr. = "statement". $ no. "and". $ type. "or all data with a price greater than 200 RMB ";
Break;
}
Break;
Case 3:
Switch ($ price)
{
Case 1:
$ Querystring. = "where no =". $ no. "and type =" ". $ type." "and price <50 ";
$ Showstr. = "all data whose price is less than 50 yuan ";
Break;
Case 2:
$ Querystring. = "where no =". $ no. "and type =" ". $ type." "and price between 50 and 200 ";
$ Showstr. = "billing method". $ no. "and". $ type. "all data with a price between 50 and 200 RMB ";
Break;
Case 3:
$ Querystring. = "where no =". $ no. "and type =" ". $ type." "and price> 200 ";
$ Showstr. = "billing method". $ no. "and". $ type. "all data with a price greater than 200 RMB ";
Break;
}
Break;
}
Break;
}
$ Result = mysql_query ($ querystring, $ linkstr );
Echo"
$ Showstr:
";
If (@ mysql_num_rows ($ result)> 0)
{
While (list ($ no, $ type, $ name, $ qty, $ price) = mysql_fetch_row ($ result ))
{
Echo"
";Echo"
";Echo"
| Billing method | ";Echo"
$ No | ";Echo"
";Echo"
";Echo"
| Differences | ";Echo"
$ Type | ";Echo"
";Echo"
";Echo"
| Accessories | ";Echo"
$ Name | ";Echo"
";Echo"
";Echo"
| Data volume | ";Echo"
$ Qty | ";Echo"
";Echo"
";Echo"
| Price | ";Echo"
$ Price | ";Echo"
";Echo"
";
}
}
?>