Php 在wordpress的特定标记中显示mysql查询

Php 在wordpress的特定标记中显示mysql查询,php,mysql,wordpress,Php,Mysql,Wordpress,这是我当前使用的查询。它的目的是获取列中所有值的百分比,并输出最高百分比值 <?php $wpdb->query( " SELECT COUNT(field1) as totals FROM test GROUP BY field1 ORDER BY totals DESC", ); ?> 这是我想要的输出: field1| 15 - 45.4% 17 - 27.2% 13 - 9.0% 12 - 9.0% 18 - 9.0% 这就是我需要HTML输出的样子: <d

这是我当前使用的查询。它的目的是获取列中所有值的百分比,并输出最高百分比值

<?php
$wpdb->query( 
"
SELECT COUNT(field1) as totals FROM test GROUP BY field1 ORDER BY totals DESC",
);
?>
这是我想要的输出:

field1|
15 - 45.4%
17 - 27.2%
13 - 9.0%
12 - 9.0%
18 - 9.0%
这就是我需要HTML输出的样子:

<div class="field1">15</div>
<div class="field2"></div>
<div class="field3"></div>... and so on
15
... 等等
我的目标是能够获取查询的输出,并将其显示在特定的div或td标记中

但是,我希望设置此项,这样我就不需要为数据库中试图显示的每个条目/字段使用单独的php文件


我还需要这是足够灵活,允许我添加额外的输入,如果我需要更新页面和添加更多信息

要获取数据的百分比,需要更改sql查询

`select round((count(*)*100)/(select count(*) from test),1) as percent from test group by field1 order by percent desc`

请提供一些测试表的数据结构。我不是PHP专家,如果我做了一些错误的事情,请随时更正我的代码。
`select round((count(*)*100)/(select count(*) from test),1) as percent from test group by field1 order by percent desc`