mysql - When Wordpress Default table, Echo Success. When Plugin Table, Echo Blank

When I used this code, the resultecho display as I wanted.<?php$user_checks = $wpdb->get_results( "SELECT

When I used this code, the result/echo display as I wanted.

<?php
$user_checks = $wpdb->get_results( 
    "
    SELECT ID, user_nicename
    FROM $wpdb->users
    "
);

foreach ( $user_checks as $user_check ) 
{
    echo $user_check->ID;
    echo $user_check->user_nicename;
}
?>

But when I choose table other then what wordpress provide e.g:

<?php
    $user_checks = $wpdb->get_results( 
        "
        SELECT id, name
        FROM $wpdb->uap_banners
        "
    );

    foreach ( $user_checks as $user_check ) 
    {
    echo $user_check->id;   
    echo $user_check->name;
    }
    ?>

The Result is blank... Did I miss something? (I'm new on wordpress)

When I used this code, the result/echo display as I wanted.

<?php
$user_checks = $wpdb->get_results( 
    "
    SELECT ID, user_nicename
    FROM $wpdb->users
    "
);

foreach ( $user_checks as $user_check ) 
{
    echo $user_check->ID;
    echo $user_check->user_nicename;
}
?>

But when I choose table other then what wordpress provide e.g:

<?php
    $user_checks = $wpdb->get_results( 
        "
        SELECT id, name
        FROM $wpdb->uap_banners
        "
    );

    foreach ( $user_checks as $user_check ) 
    {
    echo $user_check->id;   
    echo $user_check->name;
    }
    ?>

The Result is blank... Did I miss something? (I'm new on wordpress)

Share Improve this question asked Jul 7, 2020 at 5:35 MuhazaMuhaza 152 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

$wpdb does not contain any reference to custom tables. So the uap_banners property doesn't exist. You need to write in the table name the say way it was written when creating the table. So in your case that would probably be (assuming you included the database prefix):

$user_checks = $wpdb->get_results( 
    "
    SELECT id, name
    FROM {$wpdb->prefix}uap_banners
    "
);

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信