尝试从我的mysql查询(在Wordpress代码段内)回显数组值
function get_customer_gain() {
global $wpdb;
$users = $wpdb->get_results( "SELECT SUM(wp_wpdatatable_1.payback) FROM wp_wpdatatable_1");
foreach( $users as $user ) {
echo $user;
}
}
add_shortcode('customer_gain', 'get_customer_gain');
我的var_dump是: array(1){[0] => object(stdClass)#3098(1){[" SUM(wp_wpdatatable_1.payback)"] => string(6)" 183320" }}
所以基本上我试图回应那个183320号码
任何指导都将不胜感激。
由于
答案 0 :(得分:2)
您好,欢迎来到stackoverflow
您的代码必须更改为
function get_customer_gain() {
global $wpdb;
$users = $wpdb->get_results( "SELECT SUM(wp_wpdatatable_1.payback) as sumed FROM wp_wpdatatable_1");
foreach( $users as $user ) {
echo $user->sumed;
}
}
add_shortcode('customer_gain', 'get_customer_gain');
答案 1 :(得分:1)
你必须使用正确的语法$ wpdb-> get_results($ query,$ type_of_result);
查看here
编辑解释:
z <- split(df, df$y)
array_a将返回关联数组,而默认情况下它将返回作为导致问题的对象