WordPress.org

Forums

Best way to pull from a user-created table? (2 posts)

  1. thejoker101
    Member
    Posted 10 years ago #

    In the codex, there is this page on how to create a table in the database (http://codex.wordpress.org/Creating_Tables_with_Plugins). However, it fails to mention the proper - perhaps read as suggested - way of retrieving from that table.

    Suggestions?

  2. skippy
    Member
    Posted 10 years ago #

    You'd pull data from your table using the same mechanisms as used with all WordPress functions:
    <?php
    global $table_prefix;
    $mytable = $table_prefix . 'my_table_name';
    $foobar = $wpdb->get_var("SELECT COUNT(id) FROM $wpdb->$mytable WHERE foo='bar'");
    echo $foobar;
    ?>

    See the wpdb class documentation.

Topic Closed

This topic has been closed to new replies.

About this Topic