【发布时间】:2018-01-09 11:15:51
【问题描述】:
假设我的数据库表名为“mytable”,它有以下数据:
Id Name Category Points
-----------------------------------------------------------
1 ABC Good 40
2 DEF Good 20
3 GHI Bad 10
4 JKL Good 30
5 MNO Bad 20
在我的 Wordpress 页面中,我想显示以下内容:
Total Points for Good = 90
Total Points for Bad = 30
请帮忙
更新我尝试使用@user3405706 给出的代码
在我的 function.php 中用作简码
function sum_good() {
global $wpdb;
$result_good = $wpdb->get_results("Select sum(points) as good_points from mytable where category='Good'");
$haha= "Total Points for Good =".$result_good['good_points'];
return $haha;
/// do same for other category
}
add_shortcode('sumgood', 'sum_good');
但仅显示短代码:
Total Points for Good =
我做错了什么
【问题讨论】:
-
到目前为止您尝试了什么?有代码吗?
标签: php mysql database wordpress