dpvmtdu364462 2014-04-27 06:29
浏览 23
已采纳

使用MySQL Count功能

I want to count all user records and display them in tables, I am trying this code code, It displays the record for one user only, I want to display records from all users.

$u=$_POST['userid'];

$result1 = mysqli_query($con,"SELECT COUNT(user_id) as total FROM table-name where user_id=$u");

echo "<table border='1'>

</tr>

<tr>

<th>User ID</th>

<th>count</th>

</tr>";

while($row = mysqli_fetch_array($result1))
  {
  echo "<tr>";
 echo "<td>" . $u . "</td>";
  echo "<td>" . $row['total'] . "</td>";
   echo "</tr>";
  }
echo "</table>";
}
  • 写回答

2条回答 默认 最新

  • dqd22496 2014-04-27 06:33
    关注

    Try the following SQL Query:

    SELECT `user_id`, COUNT(`user_id`) as `total` FROM `table-name` GROUP BY `user_id`;
    

    Refer to the documentation of the GROUP BY clause.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助