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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?