I currently am working on this piece of code.
function submitSort($area, $rev, $active, $responses){
global $db;
$dbs = new DatabaseApps($db);
$conn = $dbs->getConnection();
$sort_query = "SELECT COUNT(step) AS sortCount FROM 7SChecklistTemplate WHERE grouping=1 AND area='$area' AND rev='$rev' AND active='$active'";
$results = basicQuery($sort_query, $db);
while($result = $results->fetch_assoc()){
$step = $result['sortCount'];
}
//Decode Responses
$responses_data = json_decode(stripslashes($responses));
for($i = 0; $i < $step; $i++){
${"response" . $i} = $responses_data->{$i};
for($j = 1; $j <= $step; $j++){
//This is where my problem is occurring
$query = "UPDATE 7SChecklistTemplate SET response='$response[$i]' WHERE grouping=1 AND area='$area' AND rev='$rev' AND active='$active' AND step='$j'";
$results = basicQuery($query, $db);
}
}
$dbs->closeConnection();
return array("success" => 1);
}
The way this code works is that on the front-end a survey is giving. The responses for this survey are recorded and sent to the back-end. This section of the code should decode the responses to a variable for each response. My problem is that the variable $response[$i]
is returning NULL when it should return Y, N, or NA depending on the response. My main question is, am I writing the variable right or is my for loop not performing as I expected? I know the ${"response" . $i} = $responses_data->{$i};
code is woking because if I change the return array to return array($response0)
. The return is correct based on what entry the user puts in.
0