Heim >Backend-Entwicklung >PHP-Tutorial >代码求简单化

代码求简单化

WBOY
WBOYOriginal
2016-06-13 11:54:201068Durchsuche

代码求简化

<br />	<form class="f"action="wel.php" method="get"><br />		<input class="inp" type="text" name="mindate" value="<?php echo $mindate ?>" onfocus="HS_setDate(this)" readonly="readonly"/>至<br />        <input class="inp" type="text" name="maxdate" value="<?php echo $maxdate ?>" onfocus="HS_setDate(this)" readonly="readonly"/><br />		<input class="sub" type="submit" value="统计"/><br />	</form><br />

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

<br /> <tr><br />    <td>城南东</td><br />    <td><?php echo $cndx;?></td><br />    <td><?php echo $cndf;?></td><br />    <td><?php echo $cnds;?></td><br />    <td><?php echo $cndm;?></td><br />  </tr><br />  <tr><br />    <td>城南西</td><br />    <td><?php echo $cnxx;?></td><br />    <td><?php echo $cnxf;?></td><br />    <td><?php echo $cnxs;?></td><br />    <td><?php echo $cnxm;?></td><br />  </tr><br />

------解决方案--------------------
查询那块写成函数不是更好点吗
------解决方案--------------------
$sql = "SELECT area, type, count(*) AS count FROM `khxx` WHERE dates>=‘$mindate’ and dates

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn