• burrowsja

    (@burrowsja)


    This should be simple. I copied and pasted the below code from the codex page on $wpdb into a template and it returns the correct $user_count variable:

    <?php
    $user_count = $wpdb->get_var($wpdb->prepare(“SELECT COUNT(*) FROM $wpdb->users;”));
    echo ‘<p>User count is ‘ . $user_count . ‘</p>’;
    ?>

    I’ve created a table (wp_designers) and tried to call exactly the same query as above on this table but it returns nothing:

    <?php
    global $wpdb;
    $user_count = $wpdb->get_var($wpdb->prepare(“SELECT COUNT(*) FROM $wpdb->designers;”));
    echo ‘<p>User count is ‘ . $user_count . ‘</p>’;
    ?>

    Can someone please tell me what I’m missing?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Not part of my plugin.

    Problem is that $wpdb->designers is not known.

    global $wpdb;
    $user_count = $wpdb->get_var($wpdb->prepare(“SELECT COUNT(*) FROM “.$wpdb->prefix.”designers;”));
    echo ‘<p>User count is ‘ . $user_count . ‘</p>’;

    use this 😉

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Getting data from using $wpdb from my created table’ is closed to new replies.