2017-04-17 2 views
0

Ich habe 4 Tabellen.PHP Mysql Wählen Sie mehrere Tabelle und multidimensionales Array

Student (id_student, Name)

Subjekt (id_subject, subject_name)

subject_category (id_subject_category, id_subject, subject_category)

Score (id_score, id_student, id_subject, id_subject_category, score)

Das Ergebnis ist

Array 
(
    [final] => Array 
     (
      [0] => Array 
       (
        [id] => 1 
        [name] => John 
        [score] => Array 
         (
          [0] => Array 
           (
            [id_score] => 1 
            [id_student] => 1 
            [id_subject] => 2 
            [id_subject_category] => 1 
            [score] => 90 
           ) 
          [1] => Array 
           (
            [id_score] => 2 
            [id_student] => 1 
            [id_subject] => 2 
            [id_subject_category] => 2 
            [score] => 70 
           ) 
          [2] => Array 
           (
            [id_score] => 3 
            [id_student] => 1 
            [id_subject] => 2 
            [id_subject_category] => 3 
            [score] => 60 
           ) 


         ) 

       ) 

     ) 

) 

muss ich Array wie diese diese

Array 
(
    [final] => Array 
     (
      [0] => Array 
       (
        [id] => 1 
        [name] => John 
        [score] => Array 
         (
          [id_subject] => Array 
           (
            [0] => Array 
             (
              [id_score] => 1 
              [id_student] => 1 
              [id_subject_category] => 1 
              [score] => 90 
             ) 
            [2] => Array 
             (
              [id_score] => 2 
              [id_student] => 1 
              [id_subject_category] => 2 
              [score] => 70 
             ) 
            [3] => Array 
             (
              [id_score] => 3 
              [id_student] => 1 
              [id_subject_category] => 3 
              [score] => 60 
             ) 

           ) 

         ) 

       ) 

     ) 

) 
+0

was ist der Unterschied zwischen denen ich glaube, nur die Tasten richtig? – Omi

Antwort

0

machen Versuchen

public function score(){ 
$this->db->select('*'); 
$this->db->from('student'); 
$query0 = $this->db->get(); 
$data=$query0->result_array(); 
$j = 0; 


while($j<count($data)){ 
    $sql2= "SELECT * FROM score where score.id_student = ?"; 
    $data2 = $this->db->query($sql2,$data[$j]['id_student']);   
    $data2 = $data2->result_array(); 
    $data[$j]['score'][$data[$j]['id_student']] = $data2; 
    $j++; 
    } 
return $data; 
}