How to get row value from wpdb

I want to echo 'yes' if the "notification" row value is 1I tried to do with this code:global $wpdb;$

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 Do you want to do this check for a currently logged in user? Currently, your SQL query pulls all of the users from wp_users table. – Greg Winiarski Commented Aug 5, 2019 at 13:42
  • 1 In your code $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 column notification. – nmr Commented Aug 5, 2019 at 13:50
Add a comment  | 

1 Answer 1

Reset to default 0

As @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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745265835a4619449.html

相关推荐

  • How to get row value from wpdb

    I want to echo 'yes' if the "notification" row value is 1I tried to do with this code:global $wpdb;$

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信