这是我的第一篇文章,希望有人能提供帮助。我正在查询 mySQL 数据库中的表,显然得到了结果。然而,该表用于存储一个用户的多个条目,以用于用户联系人的目的。
我想要做的是单独显示每个用户,并计算每个用户拥有的联系人数量。我查看了帖子“如何检测 PHP 数组中的重复帖子”,这有点帮助,但我仍然陷入困境。
请参阅下面的查询代码,我省略了数组重复部分,因为它目前非常困惑。
<?php
$result = mysql_query("SELECT * FROM vines");
while($row = mysql_fetch_array($result)) {
$results=$row['vinename'];
echo $results;
echo "<br />";
}
?>
该结果返回以下内容,显然这些是 vinename 列中的记录。
Marks Vine<br />
Marks Vine<br />
Marks Vine<br />
Tasch Vine<br />
Tasch Vine<br />
问候 马克·洛克斯顿
最佳答案
Hi there, my first post here and hoping someone can help. I am querying a table in a mySQL DB, and obviously getting the results. However, the table is used to store multiple entry by one user for the purpose of user contacts.
您可以在查询本身中比在之后的 PHP 代码中更轻松地执行此操作。
SELECT name, COUNT(id) AS count FROM vines GROUP BY name
关于mysql - PHP 数组重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1639134/