I have two tables- One with attendance details and another one with student detail. The following are the table structures:
tbl_attendance
aid date attendance
1 2017-03-09 5,6,9
2 2017-04-06 12,6,10
tbl_students
student_id name
5 John
6 Bryan
9 Anna
10 Mathew
12 Susan
Now, I want to display the names of the absentees in the view as something like say. for example:
Date Absentees
2017-03-09 John, Bryan, Anna
2017-03-06 Susan, Bryan, Mathew
I was trying to do it with FIND_IN_SET()..but it seems bad luck..Is there a better way to sort this out?
UPDATE
I used this query instead and it echoed only the first id's name in each row...
$query = $this->db
->select("tbl_attendance.*,tbl_students.name")
->from("tbl_attendance")
->join("tbl_students","tbl_students.student_id=tbl_attendance.attendance")
->where('FIND_IN_SET(tbl_students.student_id, tbl_attendance.attendance)')
->GROUP_BY('tbl_students.student_id')
->get()->result_array();
But as there are three numbers separated by commas in each row I want the rest to be echoed as well.