在PHP mySQL中计算表记录值并将计数值分配为变量

时间:2015-05-22 05:30:20

标签: php html sql count

我有一个数据库,其中包含州名,区,城市,区域大小等区域详细信息......

现在我想从州名中计算一个区域值,并将该值分配给某个变量以显示html页面。

Example: The tamil nadu state includes total of 30 districts. 

查询状态列表,

$qry = "SELECT DISTINCT state_Name FROM area_info ORDER BY state_Name";

怎么做...有人请帮助我..

5 个答案:

答案 0 :(得分:2)

尝试此查询:

SELECT count(district) 
FROM area_info 
GROUP BY state_Name

答案 1 :(得分:2)

试试这个

$qry = "SELECT DISTINCT state_Name, COUNT(*) AS district  FROM area_info Group BY state_Name" ;

答案 2 :(得分:2)

要获取记录的计数,您可以使用以下查询

echo "The tamil nadu state includes total of $totaldist districts.";

然后分配这个变量你可以这样写:

{{1}}

答案 3 :(得分:2)

您应该尝试这一点,肯定会解决您的疑问。

$qry = "SELECT state_name, COUNT(district) As TotalData FROM area_info GROUP BY state_name";

答案 4 :(得分:1)

列出州名及其中的地区数量:

SELECT state_Name, COUNT(district)
FROM area_info
GROUP BY state_Name;