如何将Count(*)作为从SQL到php的变量? [英] How to take Count (*) as variable from SQL to php?

查看:116
本文介绍了如何将Count(*)作为从SQL到php的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已向SQL请求:

SELECT meta_value,  COUNT(*)  from wp_postmeta; 

并有一个响应数组:

array (size=102)
  0 => 
    object(stdClass)[24]
      public 'meta_value' => string '37' (length=2)
      public 'COUNT(*)' => string '147' (length=3)
  1 => 
    object(stdClass)[23]
      public 'meta_value' => string '32' (length=2)
      public 'COUNT(*)' => string '143' (length=3)

我使用"meta_value"在使用php代码时没有任何麻烦:

I take "meta_value" without any troubles with php code:

$result->meta_value;

但是如何获取公共'COUNT(*)' =>字符串'143'(length = 3)的值? 我尝试了不同的语法和仅一些错误.

But how take values of public 'COUNT(*)' => string '143' (length=3)? I have tried different syntaxis and some errors only.

我需要值:147,143 ...

推荐答案

使用AS创建别名

SELECT meta_value,  COUNT(*) As count  from wp_postmeta; 

然后使用count

这篇关于如何将Count(*)作为从SQL到php的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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