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

编程入门 行业动态 更新时间:2024-10-11 23:23:50
本文介绍了从php中的mysql表中选择count(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我可以得到mysql查询结果的值和行。

但我很难得到查询的单个输出。例如:

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

我需要显示结果。但我没有得到结果。

我尝试了以下方法:

  • mysql_fetch_assoc()
  • mysql_free_result
  • mysql_fetch_row()
  • 您需要使用别名来对聚合进行别名,作为关键字,以便从 mysql_fetch_assoc

    中调用

    $ result = mysql_query(SELECT count(*)as total from Students); $ data = mysql_fetch_assoc($ result); echo $ data ['total'];

    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:

  • mysql_fetch_assoc()
  • mysql_free_result()
  • mysql_fetch_row()
  • But I didn't succeed to display (get) the actual value.

    解决方案

    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'];

    更多推荐

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

    本文发布于:2023-11-22 02:21:24,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1615595.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:php   mysql   count

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!