I am working on one of my old php projects where I used GROUP BY head_id that was working fine, but now it's showing nothing but blank page while executing. Showing results while I am trying GROUP BY id instead of head_id or anything else.
if(isset($_POST['submit'])) {
$start = mysqli_real_escape_string($conn, $_POST['start']);
$end = mysqli_real_escape_string($conn, $_POST['end']);
$sql = "SELECT *
FROM bill_info
WHERE date(updated_on) BETWEEN '$start' AND '$end' AND is_paid='1'
GROUP BY head_id";
$res = mysqli_query($conn, $sql);
}
while ($data = mysqli_fetch_array($res)) {
echo $data['head_id']." - ".$data['amount'];
}
Only if I am trying to GROUP BY id then it's working fine but showing nothing while trying to GROUP BY head_id. There are lots of rows for same head_id, that's why I need to group them, otherwise report is becoming too long.
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||----------------------------------------------------------- Updated !!! --------------------------------------------------------- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The query given below is working fine for me.
$sql = "SELECT head_id, sum(amount), sum(student_no) FROM bill_info WHERE date(updated_on) BETWEEN '$start' AND '$end' AND is_paid='1' GROUP BY head_id";
I have tried to select other columns except head_id or aggregate function, but it doesn't work!