admin管理员组文章数量:1325367
I am trying to build a shortcode that will query a db and sum. Here is what I have so far:
function my_plugin_name_count_people() {
global $wpdb;
return $wpdb->query ("SELECT COALESCE(SUM(`column_one`), column_two ,0) FROM `table_name` WHERE `booking_date` = CURDATE() -10");
}
add_shortcode('countpeople', 'my_plugin_name_count_people');
This returns '1' as the value but if I run the statement in myphpadmin then it shows NULL. That is accurate since there are no results for that day. Anyone know why it is showing '1' on the SUM() count?
I am trying to build a shortcode that will query a db and sum. Here is what I have so far:
function my_plugin_name_count_people() {
global $wpdb;
return $wpdb->query ("SELECT COALESCE(SUM(`column_one`), column_two ,0) FROM `table_name` WHERE `booking_date` = CURDATE() -10");
}
add_shortcode('countpeople', 'my_plugin_name_count_people');
This returns '1' as the value but if I run the statement in myphpadmin then it shows NULL. That is accurate since there are no results for that day. Anyone know why it is showing '1' on the SUM() count?
Share Improve this question edited Aug 12, 2020 at 9:41 mozboz 2,6281 gold badge12 silver badges23 bronze badges asked Aug 12, 2020 at 0:51 BobBob 134 bronze badges1 Answer
Reset to default 0You need to read the manual for the functions you're using as all the information for how to debug is contained there.
$wpdb-query()
description is very clear. The return value is:
(int|bool) Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows affected/selected for all other queries. Boolean false on error.
As mentioned in answers to your previous questions, you probably want something like $wpdb->getvar()
, which returns one scalar value from a query.
本文标签: phpwpdbgtquery returns different value to phpMyAdmin
版权声明:本文标题:php - wpdb->query returns different value to phpMyAdmin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742193260a2430605.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论