Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter vikrant 9

    (@vikrant-9)

    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

    (@martynasma)

    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

    (@vikrant-9)

    Thanks

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

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