PHP: analyse variable -
i creating website school.
i have subjects of student saved in database.
it's saved --> 1,2,3,6,7
this means student x subject id 1,2,3, 6 , 7
the subjects 1 student returned database in 1 variable $subjects output subject name (subject names stored in database). since variable returned in $subjects not 1 subject, multiple, can't search subject name. possible convert $subjects array $subjects[0] 1 in example , $subjects[1] 2 (see above @ it's saved this).
simply said: should not $subjects = 1,2,3,6,7 but
$subjects[0] = 1 $subjects[1] = 2 $subjects[2] = 3 $subjects[3] = 6 $subjects[4] = 7
you can use explode convert string array:
explode(',', $students);
it should noted, however, exploding , doing more queries database subject names inefficient way this. rather store students subjects in 1 field should create whole table relationship. in additional students table , subjects table, have relationship:
table: studentsubjects
student | subject ----------------- 1 | 1 1 | 2 1 | 3 1 | 6 1 | 7 2 | 2 2 | 4 2 | 6 2 | 8 3 | 3
then can query database , list of subject names particular student, or group of students, in 1 query.
Comments
Post a Comment