Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

how add row below each group in table that show count query results [duplicate]

$
0
0

I have a database table for record classes attendance in school. like this:database table

codenamedateclassattendance
101john01-03-2023mathabsent
101john01-03-2023geometryPresent
101john02-03-2023mathClosed
101john02-03-2023geometryPresent
102smith01-03-2023GeographyPresent
102smith01-03-2023HistoryPresent
102smith01-03-2023literatureClosed
102smith02-03-2023GeographyPresent
102smith02-03-2023Historyabsent
102smith02-03-2023literatureabsent

I run query (MYSQL) with php for count that show data as group by name and classes in html table. like this:html table

nameclassPresentabsentclosed
johnmath011
johngeometry200
smithGeography200
smithHistory110
smithliterature101

I want add row below each name that count sum of her attendance. like this:i want this

nameclassPresentabsentclosed
johnmath011
johngeometry200
john211
smithGeography200
smithHistory110
smithliterature101
smith411

please guide me!

I tried ROLLUP but that work only for number not string like absent, presnt ...

Last Update:this is my php code:

<?php$sql = "SELECT code, name, class FROM attendance GROUP BY name, class";$result = $mysqli -> query($sql);$row = $result ->fetch_assoc();?><table><thead><tr><th>Name</th><th>class</th><th>Present</th><th>absent</th><th>closed</th></tr></thead><tbody><?php        foreach($row as $k) {            $code = $row["code"];            $class = $row["class"];    ?><tr><td><?php echo $row["name"];?></td><td><?php echo $row["class"];?></td><td><?php $sql2 = "SELECT count(*) from attendance WHERE code = '$code' AND class = '$class' AND attendance = 'Present'";                $result2 = $mysqli -> query($sql2);                $count2= $result2 ->num_rows;                echo $count2; ?></td><td><?php $sql3 = "SELECT count(*) from attendance WHERE code = '$code' AND class = '$class' AND attendance = 'absent'";                $result3 = $mysqli -> query($sql3);                $count3= $result3 ->num_rows;                echo $count3; ?></td><td><?php $sql4 = "SELECT count(*) from attendance WHERE code = '$code' AND class = '$class' AND attendance = 'closed'";                $result4 = $mysqli -> query($sql4);                $count4= $result4 ->num_rows;                echo $count4; ?></td></tr><?php        }        ?></tbody></table>

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>