显示当月的总行

我需要按月显示数据库排序中的总行数。


有我的代码:


 <?php

 $sql = "SELECT aptName FROM property WHERE status='Sold' GROUP BY MONTH(createdate)";

 if ($result=mysqli_query($con,$sql))

 {

 $rowcount=mysqli_num_rows($result);

 printf("%d\n",$rowcount);

 mysqli_free_result($result);

 }

 ?>

我想显示当月有多少房产售罄。下个月同样的事情等等..


呼啦一阵风
浏览 194回答 2
2回答

守候你守候我

如果您使用的是 MySQL,您可以尝试以下查询:&nbsp;SELECT count(*) tot_apt_in_month&nbsp; &nbsp; &nbsp;FROM property&nbsp;&nbsp; &nbsp; &nbsp;WHERE status='Sold'&nbsp;&nbsp; &nbsp; &nbsp;AND MONTH(createdate) = month(curdate())要查看结果,您至少应该查看echo行内容:&nbsp; while($row = $result->fetch_array())&nbsp; {&nbsp; echo $row['tot_apt_in_month'];&nbsp; echo "<br />";&nbsp; }或者&nbsp; &nbsp; &nbsp;"SELECT MONTH(createdate) my_month, count(*) tot_apt_in_month&nbsp; &nbsp; &nbsp;FROM property&nbsp;&nbsp; &nbsp; &nbsp;WHERE status='Sold'&nbsp;&nbsp; &nbsp; &nbsp;AND MONTH(createdate) = month(durdate())&nbsp; &nbsp; &nbsp;GROUP BY MONTH(createdate)&nbsp; &nbsp; &nbsp;";&nbsp; while($row = $result->fetch_array())&nbsp; {&nbsp; &nbsp; &nbsp; echo $row['my_month'] . " " . $row['tot_apt_in_month'];&nbsp; &nbsp; &nbsp; echo "<br />";&nbsp; }

Smart猫小萌

您可以使用以下查询,该查询将返回包含月份和已售物业数量的多条记录。SELECT count(id) soldPropertyCount, MONTHNAME(createdate)FROM property WHERE status='Sold' GROUP BY MONTH(createdate)希望对你有帮助!!
打开App,查看更多内容
随时随地看视频慕课网APP