admin管理员组文章数量:1417421
I want to echo 'yes' if the "notification" row value is 1
I tried to do with this code:
global $wpdb;
$row =$wpdb->get_results("SELECT * FROM wp_users");
if($row['notification'] == 1){
echo 'yes';
}
I want to echo 'yes' if the "notification" row value is 1
I tried to do with this code:
global $wpdb;
$row =$wpdb->get_results("SELECT * FROM wp_users");
if($row['notification'] == 1){
echo 'yes';
}
Share
Improve this question
asked Aug 5, 2019 at 13:07
MichaelMichael
1
2
|
1 Answer
Reset to default 0As @nmr says, $row is an array of objects. You'll need to foreach these - and do the check in the foreach like this:
foreach ($row as $item) {
if($item->notification == '1') {
echo 'Yes';
}
}
And there's no "notification" column as far as I know.
Also, can you explain what you're trying to achieve? Maybe there's an easier way to achieve your goal.
Best regards
本文标签: How to get row value from wpdb
版权声明:本文标题:How to get row value from wpdb 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745265835a2650594.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$row
is array of objects. To get for example login field from first result you should use$login = $row[0]->user_login;
. Look here,get_results()
returns array of objects or array of arrays. And the second thing, in users table there is no columnnotification
. – nmr Commented Aug 5, 2019 at 13:50