I have a csv in such a format. I am trying to build an html table like show below.
Sem 1 , Subj 1 , 75 , 100 ;
Sem 1 , Subj 2 , 95 , 100 ;
Sem 1 , Subj 3 , 88 , 100 ;
Sem 2 , Subj 2 , 95 , 100 ;
Sem 2 , Subj 3 , 85 , 100 ;
Sem 3 , Subj 4 , 87 , 100 ;
Sem 4 , Subj 1 , 84 , 100 ;
HTML Table
Sem 1 Sem 2 Sem 3 Sem 4
Subj 1 75 X X 84
Subj 2 95 95 X X
Subj 3 88 85 X X
Subj 4 X X 87 X
// This is what i have came up with . Which is currently printing only the heading
$datas = [
["Sem 1" , "Subj 1" , "75" , "100"],
["Sem 1" , "Subj 2" , "95" , "100"],
["Sem 1" , "Subj 3" , "88" , "100"],
["Sem 2" , "Subj 2" , "95" , "100"],
["Sem 2" , "Subj 3" , "85" , "100"],
["Sem 3" , "Subj 4" , "87" , "100"],
["Sem 4" , "Subj 1" , "84" , "100"]];
$unique_coloum = [];
echo "<tr>";
foreach($datas as $data){
if(!in_array($data[0],$unique_coloum)){
echo "<td>".$data[0]."</td>";
array_push($unique_coloum,$data[0]);
}
}
echo "</tr>";
foreach($datas as $data){
#?
}
The Sem and Subj are n. I am stuck at for loop logic on how about to start. Any help would be great.
question from:
https://stackoverflow.com/questions/65869680/html-table-printing-from-array