Title: php script that loads data from database
Last modified: August 24, 2016

---

# php script that loads data from database

 *  Resolved [vikrant 9](https://wordpress.org/support/users/vikrant-9/)
 * (@vikrant-9)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/php-script-that-loads-data-from-database/)
 * My Php Script is
 * <?php
    global $wpdb; $myrows=$wpdb->get_results(“SELECT answer FROM {$prefix}
   wp_modal_survey_answers”, ARRAY_A); // Print it as JSON foreach{$myrows as $key1
   echo json_encode( $key1[‘answer’] ); }
 * ?>
 * I want to load data from the database to form chart.
 * **On javascript section i am using this code**
 * var %CHART% = AmCharts.makeChart(“%CHART%”, {
    “dataLoader”: { “url”: “[http://www.abc.com/wp-content/themes/decor-child/data.php&#8221](http://www.abc.com/wp-content/themes/decor-child/data.php&#8221);,“
   format”: “json” }, “graphs”: [{ “valueField”: “answer”
 *  }]
 * });
 * ON Resources section i have used these files
 * [http://www.amcharts.com/lib/3/amcharts.js](http://www.amcharts.com/lib/3/amcharts.js)
   
   [http://www.amcharts.com/lib/3/serial.js](http://www.amcharts.com/lib/3/serial.js)
   [http://cdn.amcharts.com/lib/3/plugins/dataloader/dataloader.min.js](http://cdn.amcharts.com/lib/3/plugins/dataloader/dataloader.min.js)
 * In HTML section
 * <div id=”%CHART%” style=”width: 100%; height: 300px;”></div>
 * but my chart is not appearing please suggest me solution
    Thanks
 * [https://wordpress.org/plugins/amcharts-charts-and-maps/](https://wordpress.org/plugins/amcharts-charts-and-maps/)

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

 *  Thread Starter [vikrant 9](https://wordpress.org/support/users/vikrant-9/)
 * (@vikrant-9)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/php-script-that-loads-data-from-database/#post-5966288)
 * PHP SCRIPT IS
 * <?php
    global $wpdb; $myrows=$wpdb->get_results(“SELECT answer FROM {$prefix}
   wp_modal_survey_answers”, ARRAY_A); // Print it as JSON foreach($myrows as $key1){
   echo json_encode( $key1[‘answer’] ); }
 * ?>
 *  Plugin Author [martynasma](https://wordpress.org/support/users/martynasma/)
 * (@martynasma)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/php-script-that-loads-data-from-database/#post-5966375)
 * The reason why it’s not working is that your are outputting each data row as 
   a separate JSON object. Try this instead:
 *     ```
       <?php
       global $wpdb;
       $myrows=$wpdb->get_results("SELECT answer FROM {$prefix}wp_modal_survey_answers", ARRAY_A);
       // Print it as JSON
       $json = array();
       foreach($myrows as $key1){
         $json[] = $key1['answer'];
       }
       echo json_encode( $json );
       ?>
       ```
   
 * There may be some other issues besides that as well. Like for instance there 
   does not seems to be any category field.
 *  Thread Starter [vikrant 9](https://wordpress.org/support/users/vikrant-9/)
 * (@vikrant-9)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/php-script-that-loads-data-from-database/#post-5966472)
 * Thanks

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

The topic ‘php script that loads data from database’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/amcharts-charts-and-maps_6f74b0.svg)
 * [amCharts: Charts and Maps](https://wordpress.org/plugins/amcharts-charts-and-maps/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amcharts-charts-and-maps/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amcharts-charts-and-maps/)
 * [Active Topics](https://wordpress.org/support/plugin/amcharts-charts-and-maps/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amcharts-charts-and-maps/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amcharts-charts-and-maps/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [vikrant 9](https://wordpress.org/support/users/vikrant-9/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/php-script-that-loads-data-from-database/#post-5966472)
 * Status: resolved