Title: [Plugin: Custom List Table Example] Help using plugin (error message with sql instead of example $da
Last modified: August 20, 2016

---

# [Plugin: Custom List Table Example] Help using plugin (error message with sql instead of example $da

 *  [redconservatory](https://wordpress.org/support/users/redconservatory/)
 * (@redconservatory)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-help-using-plugin-error-message-with-sql-instead-of-example-data/)
 * I’ve installed the plugin and it works great with the example data.
 * However, when I try to use my own sql in the prepare_items function I am getting
   an error:
 * `Fatal error: Cannot use object of type stdClass as array`
 * It seems like the example data is an array that contains arrays
    i.e.
 *     ```
       var $example_data = array(
                   array(
                       'ID'        => 1,
                       'title'     => '300',
                       'rating'    => 'R',
                       'director'  => 'Zach Snyder'
                   ),
                   array(
                       'ID'        => 2,
                       'title'     => 'Eyes Wide Shut',
                       'rating'    => 'R',
                       'director'  => 'Stanley Kubrick'
                   ),
       ```
   
 * But when I write:
 *     ```
       global $wpdb;
       		  $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'name'; //If no sort, default to title
                 $sql = "SELECT * FROM wp_nc_location ORDER BY " . $orderby;
       		  $data = $wpdb->get_results($sql);
       ```
   
 * My $data is an array that contains objects, print_r and gettype on $data reveals
 * data is Array ( [0] => stdClass Object ( …) [1] => stdClass Object ( …) )
 * Can anyone help?
 * [http://wordpress.org/extend/plugins/custom-list-table-example/](http://wordpress.org/extend/plugins/custom-list-table-example/)

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

 *  Thread Starter [redconservatory](https://wordpress.org/support/users/redconservatory/)
 * (@redconservatory)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-help-using-plugin-error-message-with-sql-instead-of-example-data/#post-2245143)
 * Wait, it appears that switching it from an object to an array helped:
 * function column_default($item, $column_name){
    $item = (array)$item; }
 * Is that considered a ‘hack’ way of doing this, or is this all right?
 *  Plugin Author [Dutch van Andel](https://wordpress.org/support/users/veraxus/)
 * (@veraxus)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-help-using-plugin-error-message-with-sql-instead-of-example-data/#post-2245365)
 * Casting some types of objects as arrays is technically valid.
 * You can also specify what output type (_object _vs _array_) you want `get_results()`
   to return, so that no additional casting is necessary. Like so:
 *     ```
       $data = $wpdb->get_results($sql, ARRAY_A);
       ```
   
 * This example returns an _indexed array_ of all records, and the records themselves
   are _associative_ arrays (just like the sample data used in the plugin).
 * [Take a look at this codex entry for more ideas >>](http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results)

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

The topic ‘[Plugin: Custom List Table Example] Help using plugin (error message 
with sql instead of example $da’ 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/)

 * 2 replies
 * 2 participants
 * Last reply from: [Dutch van Andel](https://wordpress.org/support/users/veraxus/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-help-using-plugin-error-message-with-sql-instead-of-example-data/#post-2245365)
 * Status: not resolved