douhe5092 2011-08-02 05:45
浏览 279
已采纳

从php中的mysql表中选择count(*)

I am able to get both the value and row of the mysql query result.

But I am struggling to get the single output of a query. e.g.:

$result = mysql_query("SELECT COUNT(*) FROM Students;");

I need the result to display. But I am not getting the result.

I have tried with the following methods:

  1. mysql_fetch_assoc()
  2. mysql_free_result()
  3. mysql_fetch_row()

But I didn't succeed to display (get) the actual value.

  • 写回答

16条回答 默认 最新

  • dpr77335 2011-08-02 05:48
    关注

    You need to alias the aggregate using the as keyword in order to call it from mysql_fetch_assoc

    $result=mysql_query("SELECT count(*) as total from Students");
    $data=mysql_fetch_assoc($result);
    echo $data['total'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(15条)

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答