WordPress.org

Ready to get started?Download WordPress

Forums

Custom List Table Example
query the database (8 posts)

  1. designerken
    Member
    Posted 2 years ago #

    Would someone mind helping me properly add a query to the database?
    Do I comment out line 373 and 384-390 and insert my function after line 400? Some help guiding me in the right direction would be very appreciated.

    http://wordpress.org/extend/plugins/custom-list-table-example/

  2. Madsex83
    Member
    Posted 1 year ago #

    Hi, i have the same problem, i don't understand how to do a query to my db and show result in the table.

    Have you find a solution?

    Thanks

  3. superpotion
    Member
    Posted 1 year ago #

    To use a proper database connection, do the following:

    At about line 317, inside function prepare_items(), insert:

    global $wpdb;

    Then, replace line 361 with something like this:

    $querydata = $wpdb->get_results(
    	"
    	SELECT * FROM wp_my_movie_table WHERE 1
    	"
    );

    The example plugin used a nested array to hold the data, but the database query will return an array of objects. It is probably better to use the objects directly, but now we'll simply re-cast so that the plugin still works without changing code elsewhere..

    Insert after the database query:

    $data=array();
    foreach ($querydata as $querydatum ) {
       array_push($data, (array)$querydatum);}

    Don't forget to create the wp_my_movie_table database table.

    It should work now, and you can go back and clean up the unnecessary code that references $example_data.

  4. superpotion
    Member
    Posted 1 year ago #

    This example is excellent, but would be vastly more useful with auto table creation and removal, complete CRUD functionality, etc.

  5. sohail_mubeen
    Member
    Posted 1 year ago #

    @superpotion thanks for your help can you please help me how i can edit or delete via this example?

  6. Matt van Andel
    Member
    Plugin Author

    Posted 1 year ago #

    The plugin foregoes any kind of database direction since a basic understanding of WordPress's $wpdb object is both a bit of a given and a different topic entirely.

    You can read up on WordPress's database object here: http://codex.wordpress.org/Class_Reference/wpdb

    While it's no Zend or CakePHP, it's fairly easy to get the hang of.

  7. Naved Ahmed
    Member
    Posted 1 year ago #

    Thanks a lot for this.....
    I've googled it since 1 days.... and didnt find anything good...
    But this works for me .....
    THANKS THANKS THANKS....... :D

  8. janhoos
    Member
    Posted 1 year ago #

    Thanks Supermotion Member. Got it to work as well. Now to find out how I can actually edit and delete things :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic