简体   繁体   English

无法回显wpdb结果

[英]can't echo wpdb result

I'm pulling information from the WordPress database. 我正在从WordPress数据库中获取信息。 It's definitely pulling all the correct information and if I display the information with print_r( $res, true ) it shows what i require which is: 它肯定会拉出所有正确的信息,如果我用print_r( $res, true )显示信息,它会显示我需要的是:

[term_id] => 8 [name] => Africa [slug] => africa [COUNT(a.id)] => 1 [term_id] => 8 [name] =>非洲[slug] =>非洲[COUNT(a.id)] => 1

I need to echo the COUNT(a.id) but I can't seem to manage this? 我需要回显COUNT(a.id)但是我似乎无法管理它? My full code is here: http://pastie.org/4121409 我的完整代码在这里: http : //pastie.org/4121409

I have managed to echo all the other information, just not the COUNT(a.id) 我设法回显了所有其他信息,而不是COUNT(a.id)

Thanks in advance! 提前致谢!

When selecting, use column aliases, like this: COUNT(a.id) AS id_count 选择时,请使用列别名,例如: COUNT(a.id) AS id_count

Then it will appear as the field name in result set, instead of COUNT(a.id) and you will be able to access it by $rs->id_count 然后它将显示为结果集中的字段名称,而不是COUNT(a.id) ,您将可以通过$rs->id_count访问它

Also note that in your original code, line 22 will break the code. 另请注意,在您的原始代码中,第22行将破坏该代码。 It should have been $counter = "COUNT(a.id)"; 应该是$counter = "COUNT(a.id)";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM