First, I would like to mention that I'm terrible at PHP but I'm trying my best to work with it. For some reason I can get information from an array in PHP but I just can't extract information from an array within an array..
So here's the page that var_dumps the array: http://www.farahfa.com/iplanner/webservice/assign_blah.php
And I want to extract all the information in that inner array but I can't figure out how to do it..
Here's my code so far.
<?php
include_once "../config/config.php";
// Expected from the app: student_id & assignment_date
$student_id = $_POST['student_id'];
$assignment_date = $_POST['assignment_date'];
$return=[];
$sql = "SELECT DISTINCT
s1.name AS subject,
a.id AS assignmentID,
sa.id AS subjectAssignID,
sa.content AS content,
sa.due_date AS dueDate,
a.general_teacher_note AS generalNote,
sn.note_content AS specificNote,
sub.isSigned AS isSigned
FROM student AS s
LEFT JOIN enrollment AS e ON e.id = e.student_id
LEFT JOIN classroom AS c ON c.id = e.classroom_id
LEFT JOIN assignment AS a ON c.id = a.classroom_id
LEFT JOIN submission AS sub ON a.id = sub.assignment_id
LEFT JOIN specific_notes AS sn ON a.id = sn.assignment_id
LEFT JOIN subject_assignment AS sa ON a.id = sa.assignment_id
LEFT JOIN subject_class AS sc ON sc.id = sa.subject_class_id
LEFT JOIN subject AS s1 ON s1.id = sc.subject_id
WHERE e.student_id = 2 AND a.date = '2015-04-07'";
$result = $conn->query($sql); // Execute the query
if ($result->rowCount() >= 1) // If there are data returned then do the following
{
$subject_assignments = $result->fetchAll(); // Get all the rows that are returned
var_dump($subject_assignments);
for($i = 0; $i < sizeof($subject_assignments); ++$i )
{
for($j = 0; $j < sizeof($i); ++$j )
{
/*[
['subjectAssignID' => $subject_assignments[$i][$j]['subjectAssignID'],
'subject' => $subject_assignments[$i][$j]['subject'],
'content' => $subject_assignments[$i][$j]['content'],
'dueDate' => $subject_assignments[$i][$j]['dueDate']],
['subject' => $subject_assignments[$i][$j]['subject'],
'content' => $subject_assignments[$i][$j]['content'],
'dueDate' => $subject_assignments[$i][$j]['dueDate']],
['generalNote' => $subject_assignments[$i][$j]['generalNote'],
'specificNote' => $subject_assignments[$i][$j]['specificNote'],
'assignmentID' => $subject_assignments[$i][$j]['assignmentID'],
'isDone' => $subject_assignments[$i][$j]['isDone']]
]*/
}
}
}
/*
[
[
'subjectAssignID' => '1',
'subject' => 'subjectHere',
'content' => '1',
'dueDate' => 'sdfds'
],
['subject' => 'subjectHere','content' => '1','duedate' => 'sdfds'],
],
'teacherNote' => 'Whatever',
'parentNote' => 'Note Parent'
'assignmentID' => '1'
echo json_encode($return); //Makes it a json array
} else {
echo 0;
}
*/
?>
If anyone can help me with this I'd be eternally thankful!