当前位置:Gxlcms > PHP教程 > 代码求简单化

代码求简单化

时间:2021-07-01 10:21:17 帮助过:16人阅读

代码求简化




$sql="SELECT count(*) AS count FROM `khxx` WHERE dates>='".$mindate."' and dates<='".$maxdate."' and `type`='新增' and `area`='城南东'";
$cndx=mysql_result(mysql_query($sql),0);
$sql="SELECT count(*) AS count FROM `khxx` WHERE dates>='".$mindate."' and dates<='".$maxdate."' and `type`='续费' and `area`='城南东'";
$cndf=mysql_result(mysql_query($sql),0);
$sql="SELECT count(*) AS count FROM `khxx` WHERE dates>='".$mindate."' and dates<='".$maxdate."' and `type`='升兆' and `area`='城南东'";
$cnds=mysql_result(mysql_query($sql),0);
$sql="SELECT count(*) AS count FROM `khxx` WHERE dates>='".$mindate."' and dates<='".$maxdate."' and `type`='免费' and `area`='城南东'";
$cndm=mysql_result(mysql_query($sql),0);

$sql="SELECT count(*) AS count FROM `khxx` WHERE dates>='".$mindate."' and dates<='".$maxdate."' and `type`='新增' and `area`='城南西'";
$cnxx=mysql_result(mysql_query($sql),0);
$sql="SELECT count(*) AS count FROM `khxx` WHERE dates>='".$mindate."' and dates<='".$maxdate."' and `type`='续费' and `area`='城南西'";
$cnxf=mysql_result(mysql_query($sql),0);
$sql="SELECT count(*) AS count FROM `khxx` WHERE dates>='".$mindate."' and dates<='".$maxdate."' and `type`='升兆' and `area`='城南西'";
$cnxs=mysql_result(mysql_query($sql),0);
$sql="SELECT count(*) AS count FROM `khxx` WHERE dates>='".$mindate."' and dates<='".$maxdate."' and `type`='免费' and `area`='城南西'";
$cnxm=mysql_result(mysql_query($sql),0);



城南东






城南西






------解决方案--------------------
查询那块写成函数不是更好点吗
------解决方案--------------------
$sql = "SELECT area, type, count(*) AS count FROM `khxx` WHERE dates>=‘$mindate’ and dates<=‘$maxdate’ group by area, type order by find_in_set(area, '城南东,城南西'), find_in_set(type,'新增,续费,升兆,免费')

人气教程排行