Skip to content Skip to sidebar Skip to footer

Passing Ajax Data Into A Php Array Switch Case To Process Sql Data

I have 5 HTML input fields that each have to have their own lane weight displayed accordingly. I am not sure how I need to use Ajax here, but I need to be able to send to the PHP f

Solution 1:

Actually, I think I just found an alternative way to go about this and it is working. I just returned an array in the PHP file and then am calling each array value from the AJax:

AJAX/JS

//Populate Lane Type Weight Table - JFLAYfunctiongetLaneWeight() {
$.ajax({
    url: './php/getLaneWeight.php',
    dataType:'json',
    success: function (weight) {
        document.forms['Warehouse_Worksheet'].elements['Lead-1'].value = weight[0]['SUM(weight)'];
        document.forms['Warehouse_Worksheet'].elements['Lead-2'].value = weight[1]['SUM(weight)'];
        document.forms['Warehouse_Worksheet'].elements['Poly-1'].value = weight[2]['SUM(weight)'];
        document.forms['Warehouse_Worksheet'].elements['Poly-2'].value = weight[3]['SUM(weight)'];
        document.forms['Warehouse_Worksheet'].elements['Poly-3'].value = weight[4]['SUM(weight)'];
    },
    error: function () {

    }
});
};

PHP

$lane_name = array("Lead-1","Lead-2","Poly-1","Poly-2","Poly-3");

//Define JSON array$array = array();

foreach ($lane_nameas$value) {
    $sql="SELECT SUM(weight)
        FROM bundle_lanes
        WHERE lane_name = '$value'";

    $result = mysql_query($sql) ordie ('Error'.mysql_error());

    while ($data = mysql_fetch_array($result)) {
        $array[] = $data;
    }
}

print json_encode($array);

Post a Comment for "Passing Ajax Data Into A Php Array Switch Case To Process Sql Data"