dou1908 2018-11-02 13:51
浏览 53
已采纳

试图用PHP在Wordpress中获得mySQL的平均值,对象作为数组返回,需要它作为字符串

I have a custom table in my wordpress install, and I want to get an average out of a column on the table. I'm using the following PHP:

 $latavg = $wpdb->get_results("SELECT AVG(stop_lat) FROM stops_txt"); 

However, when I want to use the average later on as a string, it returns as 'ARRAY', yet attempting to use PRINT_R to view the array reveals nothing. The Column in the table is a DECIMAL data-type, what am I missing?

  • 写回答

1条回答 默认 最新

  • dsstjqsr631426 2018-11-02 13:53
    关注

    When you just want a single variable instead of a whole row or column in wpdb, use get_var() instead:

    $latavg = $wpdb->get_var("SELECT AVG(stop_lat) FROM stops_txt"); 
    

    Here is the complete wpdb reference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问各位,如何在Jetson nano主控板的Ubuntu系统中安装PyQt5
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥150 求 《小魔指》街机游戏机整合模拟软件