可以整理SQL的语句,如把WHERE语句先独立成$sql_where,假设生成了字符串:
"and '$agexiao'< age and age < '$ageda'",可以用substr()函数整理,如:
substr($sql_where,4)就可以得到"'$agexiao'< age and age < '$ageda'".
"and '$agexiao'< age and age < '$ageda'",可以用substr()函数整理,如:
substr($sql_where,4)就可以得到"'$agexiao'< age and age < '$ageda'".
$sql = "select * from base where 0=0 ";
if($sex !="都可以")
{
$sql = $sql."and where Xingbie='$sex'";
}if($xuelid!="都可以")
{
$sql = $sql."and Xueli = '$xuelid'";
}if($agexiao!="都可以" and $ageda!="都可以")
{
$sql=$sql."and '$agexiao'< age and age < '$ageda'"; }
if($sex !="都可以")
{
$sql = $sql." and Xingbie='$sex'";
}if($xuelid!="都可以")
{
$sql = $sql." and Xueli = '$xuelid'";
}