1

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)

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
    "
);
| improve this answer | |
  • Ghosh! You an expert on this. Salute you Mr Jacob Peattie. Thank you so much. I will put your name as a credit on my blog – Muhaza Jul 7 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.