Custom List Table Example
query the database (8 posts)

  1. designerken
    Posted 4 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.


  2. Madsex83
    Posted 3 years 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?


  3. superpotion
    Posted 3 years 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:

    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
    Posted 3 years ago #

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

  5. sohail_mubeen
    Posted 3 years ago #

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

  6. Matt van Andel
    Plugin Author

    Posted 3 years 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
    Posted 3 years ago #

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

  8. janhoos
    Posted 3 years 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

  • Custom List Table Example
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic