Chartjs-Execute SQL prepared statement in AJAX

0👍

Apple one addition parameter to ajax request

$.ajax({
    url: "data.php",
    data: { 
        "ChartType": 1/*Or change to drop down selection id*/,
        "customer_id":1
    },
    type: "GET",
    success: function(response) {
        console.log(response);
    },
    error: function(xhr) {

    }
});

You can see ChartType above, pass its value dynamically for which your want to separate sql query/

Now on server side:

$cid = htmlentities ($_GET['customer_id']);
$cType = htmlentities ($_GET['ChartType']);

if($cType==1)
    $sql = sprintf("SELECT treatment_log.bdi, treatment_log.date FROM treatment_log WHERE treatment_fk = ? ORDER BY created_at");
else if($cType==2)
    $sql = sprintf("SELECT __ other column name __ WHERE cid=$cid");
else 
    $sql = sprintf("SELECT __ other column name __ WHERE cid=$cid");

I know this is not complete code, but it will give you idea how to do it.

Leave a comment