php 语句怎样查询 MySql 某字段中相同记录的数量
发布网友
发布时间:2022-05-07 19:46
我来回答
共4个回答
热心网友
时间:2022-05-07 21:15
<?php
$hostname = 'localhost';//数据库主机
$user = 'root';#用户名
$password = '666666'; #密码
$dbname = 'ads'; #数据库名
header("Content-Type: text/html; charset=gbk");
$conn = mysql_connect($hostname, $user, $password);
mysql_select_db($dbname);
mysql_query("Set Names GBK");
$sql = "Select ad_category, Count(*) As c From city2 Group By ad_category";
$rs = mysql_query($sql);
echo "<table>";
while (list($category, $count) = mysql_fetch_row($rs)){
echo "<tr><td>$category 号</td><td>$count 个</td></tr>";
}
echo "</table>";
如果你想学好PHP的话,最好不要用这种方式学习。请参见我的学习心得:
参考资料:http://blog.everalan.com/102.html
热心网友
时间:2022-05-07 22:33
Mysql COUNT()统记函数配合GROUB BY 语句!
SELECT COUNT(`ad_category`) AS `cate_count` FROM `table_name` GROUP BY `ad_category`;
热心网友
时间:2022-05-08 00:08
select count(*) from 表名 group by ad_category
热心网友
时间:2022-05-08 01:59
老大,你耍人啊。
可以直接套上去用了啦
select count(*) from city2 group by ad_category