使用PHP计算MySQL中的相同行数 [英] Count number of identical rows in MySQL with PHP

查看:155
本文介绍了使用PHP计算MySQL中的相同行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySql中有一个关键字列表的表。

I have a table in MySql with a list of keywords. Each keyword was stored in a new row once it was entered by a user on this site.

我在PHP中有以下查询:

I have the following query in PHP:

SELECT * FROM keywords GROUP BY query

它从MySql获取所有关键字,并且只显示一个重复的关键字。所以输出是:

Which gets all the keywords from MySql, and only shows one of each incase of duplicate keywords. So the output is something like:

Dog
Cat
Lion
Fong

当我使用 $ update ['query'];

但我想计算每个关键字在数据库中出现的次数,因此输出将是,例如:

But I'd like to count how many times each keyword appears in the database, so the output would be, for example:

Dog  (2)
Cat  (3)
Lion (1)
Fong (1)

我想弄清楚SQL查询应该是什么,以及如何使用PHP打印。 >

And I'm trying to figure out what the SQL query should be, and how to print it using PHP.

推荐答案

尝试此查询:

SELECT query, COUNT(1) AS rpt_count FROM keywords GROUP BY query

使用 $ update ['query'] $ update ['rpt_count']

这篇关于使用PHP计算MySQL中的相同行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆