Title: Creating wpDataTables from serialized PHP array
Last modified: August 31, 2016

---

# Creating wpDataTables from serialized PHP array

 *  Resolved [user1001](https://wordpress.org/support/users/user1001/)
 * (@user1001)
 * [10 years ago](https://wordpress.org/support/topic/creating-wpdatatables-from-serialized-php-array/)
 * I followed all step for “Creating wpDataTables from serialized PHP arrayp”
 * when I run my below listed code I do see serialized data on browser and I then
   pasted the same link to the plugin configuration page. save it. but I see 0 data
   on preview after save on wpdatatable plug-in page. why am I not getting any data
   populated?
 * what am I doing wrong? Please help me so I can validate my proof of concept and
   then buy the full version.
 *     ```
       <?php
       $sqlForManuScript = new mysqli ( 'localhost', 'databaseroot', 'password', 'test' );
       if (! $sqlForManuScript) {
       	echo "Error: Unable to connect to MySQL." . PHP_EOL;
       	echo "Debugging errno: " . mysqli_connect_errno () . PHP_EOL;
       	echo "Debugging error: " . mysqli_connect_error () . PHP_EOL;
       	exit ();
       } else {
       	echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
       	echo "Host information: " . mysqli_get_host_info ( $sqlForManuScript ) . PHP_EOL;
       }
       $result = $sqlForManuScript->query ( "SELECT Sr_No, bookname, category, Total_Pages  FROM catalog LIMIT 200" );
   
       $new_array [] = array (); // Initializing the array that will be used for the table
   
       while ( $row = $result->fetch_assoc () ) {
        // Filling in the new array entry
   
        $new_array[]= ['Sr_No'         => $row['Sr_No'],
                       'bookname' => $row ['bookname'],
                       'category' => $row ['category'],
                       'Total_Pages' => $row ['Total_Pages']];
   
       }
       $sqlForManuScript->close ();
       $serializedArray = serialize ( $new_array );
       echo $serializedArray;
   
       ?>
       ```
   
 * [https://wordpress.org/plugins/wpdatatables/](https://wordpress.org/plugins/wpdatatables/)

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

 *  Plugin Author [wpDataTables](https://wordpress.org/support/users/wpdatatables/)
 * (@wpdatatables)
 * [10 years ago](https://wordpress.org/support/topic/creating-wpdatatables-from-serialized-php-array/#post-7406312)
 * Hi there, thank you for your interst and sorry for the delay,
 * Please remove the part where you echo that successfull connection was made.
 * The output should contain ONLY the serialized array, no more messages and also
   return HTTP Responce Code = 200.
 * Hope this helps!
 *  Thread Starter [user1001](https://wordpress.org/support/users/user1001/)
 * (@user1001)
 * [10 years ago](https://wordpress.org/support/topic/creating-wpdatatables-from-serialized-php-array/#post-7406392)
 * ahh, thanks it works now! Thanks a lot. fully convinced!
 *  [tonygilgilpin](https://wordpress.org/support/users/tonygilgilpin/)
 * (@tonygilgilpin)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/creating-wpdatatables-from-serialized-php-array/#post-7406516)
 * I have the same problem . I can see the data when i run the wp_query, but when
   i use the wpdatatable it says no data
 *     ```
       <?php
   
       // Initializing the WordPress engine in a stanalone PHP file
       include('../wp-blog-header.php');
   
       // Preparing a WP_query
       $the_query = new WP_Query(
       array(
       'post_type' => 'groups', // We only want pages
       'post_parent' => 0, // We only want children of a defined post ID
       'post_count' => -1 // We do not want to limit the post count
       // We can define any additional arguments that we need - see Codex for the full list
       )
       );
   
       $return_array = array(); // Initializing the array that will be used for the table
   
       while( $the_query->have_posts() ){
   
       // Fetch the post
       $the_query->the_post();
   
       // Filling in the new array entry
       $return_array[] = array(
       'Id' => get_the_id(), // Set the ID
       'Title' => get_the_title(), // Set the title
       'Content preview with link' => get_permalink().'||'.strip_tags( strip_shortcodes( substr( get_the_content(), 0, 200 ) ) ).'...'
       // Get first 200 chars of the content and replace the shortcodes and tags
       );
   
       }
   
       // Now the array is prepared, we just need to serialize and output it
       echo serialize( $return_array );
   
       ?>
       ```
   
 *  Plugin Author [wpDataTables](https://wordpress.org/support/users/wpdatatables/)
 * (@wpdatatables)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/creating-wpdatatables-from-serialized-php-array/#post-7406517)
 * Hi,
 * Can you please check if the HTTP code is 200? WP may set it to 404 by default
   in standalone files.
 * You can force-set it to 200 by adding this line:
    `header("HTTP/1.1 200 OK");`
   anywhere before echo.

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

The topic ‘Creating wpDataTables from serialized PHP array’ is closed to new replies.

 * ![](https://ps.w.org/wpdatatables/assets/icon-128x128.gif?rev=3010404)
 * [wpDataTables - WordPress Data Table, Dynamic Tables & Table Charts Plugin](https://wordpress.org/plugins/wpdatatables/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpdatatables/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpdatatables/)
 * [Active Topics](https://wordpress.org/support/plugin/wpdatatables/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpdatatables/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpdatatables/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [wpDataTables](https://wordpress.org/support/users/wpdatatables/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/creating-wpdatatables-from-serialized-php-array/#post-7406517)
 * Status: resolved