DBOperations.php
public function studentSection($uname) {
$this->sections = array();
$stmt = $this->conn->prepare("SELECT students.id, students.lastname, sections.name AS section_name, years.name AS year_level, academic_years.start, academic_years.end FROM students INNER JOIN section_student ON students.id = section_student.student_id INNER JOIN sections ON section_student.section_id = sections.id INNER JOIN years ON sections.year_id = years.id INNER JOIN academic_years ON sections.academic_year_id = academic_years.id WHERE students.s_id = ?");
$stmt->bind_param("s", $uname);
$stmt->execute();
$result = $stmt->get_result();
$num_of_rows = $result->num_rows;
while ($row = $result->fetch_assoc()) {
return $this->sections[] = array(
'id' => $row['id'],
'lastname' => $row['lastname'],
'section' => $row['section_name'],
'year_level' => $row['year_level'],
'school_year' => $row['start']."-".$row['end']);
}
$stmt->free_result();
$stmt->close();
}
section.php
if($db->studentLogin($uname)){
$sections = $db->studentSection($uname);
$response['error'] = false;
$response['id'] = $sections['id'];
$response['lastname'] = $sections['lastname'];
$response['section'] = $sections['section'];
$response['year_level'] = $sections['year_level'];
$response['school_year'] = $sections['school_year'];
}else{
$response['error'] = true;
$response['message'] = "No Data";
}
返回值Illegal string offset
时出错。
它不会显示所有数据。
输出为{"error":false,"id":"[","lastname":"[","section":"[","year_level":"[","school_year":"["}
当我尝试return
内的$this->sections
时,它会显示等于1
的所有数据,然后将下面的return
更改为echo json_encode($this->sections)
有用。但它只显示一行。它应该显示等于1
的所有数据行。