• Resolved user1001

    (@user1001)


    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://www.ads-software.com/plugins/wpdatatables/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author wpDataTables

    (@wpdatatables)

    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

    (@user1001)

    ahh, thanks it works now! Thanks a lot. fully convinced!

    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

    (@wpdatatables)

    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.