简体   繁体   English

使用WordPress $ wpdb对象从自定义表获取结果时出错

[英]Error using WordPress $wpdb object to get result from custom table

I am trying to use $wpdb object to get results from a custom table and I get an error when I echo the result: 我试图使用$ wpdb对象从自定义表中获取结果,并且在回显结果时出现错误:

Notice: Undefined property: stdClass::$category in...

Here is the PHP code: 这是PHP代码:

global $wpdb;
$prodCat = $wpdb->get_results( 
"SELECT * FROM product_category" , OBJECT_K);
    foreach ( $prodCat as $row ){
                echo $row->category-name;
    }

Any help is appreciated. 任何帮助表示赞赏。

Never mind. 没关系。 the problem was because of my column name 'category-name, I changed it to categoryName in database and worked fine. 问题是由于我的列名是“ category-name”,我在数据库中将其更改为categoryName,并且工作正常。 It had something to do with the hyphen ' - '. 它与连字符'-'有关。

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

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