Title: [Plugin: Custom List Table Example] query the database
Last modified: August 20, 2016

---

# [Plugin: Custom List Table Example] query the database

 *  [designerken](https://wordpress.org/support/users/kcharity/)
 * (@kcharity)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-query-the-database/)
 * 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/](http://wordpress.org/extend/plugins/custom-list-table-example/)

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

 *  [Madsex83](https://wordpress.org/support/users/madsex83/)
 * (@madsex83)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-query-the-database/#post-2711173)
 * 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
 *  [superpotion](https://wordpress.org/support/users/superpotion/)
 * (@superpotion)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-query-the-database/#post-2711202)
 * 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.
 *  [superpotion](https://wordpress.org/support/users/superpotion/)
 * (@superpotion)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-query-the-database/#post-2711203)
 * This example is excellent, but would be vastly more useful with auto table creation
   and removal, complete CRUD functionality, etc.
 *  [sohail_mubeen](https://wordpress.org/support/users/sohail_mubeen/)
 * (@sohail_mubeen)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-query-the-database/#post-2711204)
 * [@superpotion](https://wordpress.org/support/users/superpotion/) thanks for your
   help can you please help me how i can edit or delete via this example?
 *  Plugin Author [Dutch van Andel](https://wordpress.org/support/users/veraxus/)
 * (@veraxus)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-query-the-database/#post-2711205)
 * 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](http://codex.wordpress.org/Class_Reference/wpdb)
 * While it’s no Zend or CakePHP, it’s fairly easy to get the hang of.
 *  [Naved Ahmed](https://wordpress.org/support/users/imnaved/)
 * (@imnaved)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-query-the-database/#post-2711206)
 * **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……. 😀
 *  [janhoos](https://wordpress.org/support/users/janhoos/)
 * (@janhoos)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-query-the-database/#post-2711216)
 * Thanks Supermotion Member. Got it to work as well. Now to find out how I can 
   actually edit and delete things 🙂

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

The topic ‘[Plugin: Custom List Table Example] query the database’ is closed to 
new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-list-table-example.svg)
 * [Custom List Table Example](https://wordpress.org/plugins/custom-list-table-example/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-list-table-example/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-list-table-example/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-list-table-example/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-list-table-example/reviews/)

 * 7 replies
 * 7 participants
 * Last reply from: [janhoos](https://wordpress.org/support/users/janhoos/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-query-the-database/#post-2711216)
 * Status: not resolved