0

I have a php here

<?php
    /* Initiate Connection */
    require 'conn.php';

    /* Filter Criteria */
    $startdate    = $_POST['startdate'];
    $enddate      = $_POST['enddate'];
    $fsp          = $_POST['fsp'];

    /* Queries */
    $query    = 'MYSQL Query Here';

    /* Generate Whole Sales Report */
    $rs    = mysqli_query($con,$query);

    /* Sales Summary */
    while ($array_data = mysqli_fetch_row($rs)) {
        $data[] =  $array_data; 
    }

    /* Output */
    echo json_encode($data);
?>

This php code outputs a data from mysql in a form of rows and columns. my question is this but before that here is my code when passing the data in a php file.

$(document).ready(function() {
    $('#btngenerate').click(function(e) {
        $.ajax({
            url: 'gen_report.php',
            type: "POST",
            datatype: 'json',
            data: {
                    startdate: 'Data',
                    enddate:   'Data',
                    fsp:       'Data'
            },
            success: 
                function(data) {
        });     
    });
});

My question here is can someone lead me in the right path? My target here is to create a format or set of codes using this codes that I can recycle. I mean use it anywhere like passing data to php retreive it and so on.

My target here is what If my myphp file is composed of multiple queries and json_encode which is where? I means json_encode1 = html_table1,json_encode2 = html_table2 and so on how can I achieve it?

TYSM

5
  • put it into two seperate arrays first, then have a master array like $return=array("table1"=>$data1, "table2"=>$data2) then json_encode that and send it back. Commented Oct 11, 2017 at 0:08
  • general rule: only json_encode the final return and send that. in one go. You cant send several json-strings after each other. Commented Oct 11, 2017 at 0:10
  • im afraid thats true so im looking forward for the best solution Commented Oct 11, 2017 at 0:11
  • related: stackoverflow.com/questions/46228169/… Commented Oct 11, 2017 at 0:11
  • tried your suggestion im on the part on where i need to call it and it does not work for me Commented Oct 11, 2017 at 0:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.