1

i'm trying to count only the variable that fit the condition but the data i'm about to count is a result from formula and not inside the database here is the code


if (isset($_GET['tanggal'])) {
    $tgl=trim($_GET['tanggal']);
    $material=trim($_GET['material']);
    $proyek=trim($_GET['proyek']);
    $sql="SELECT *, count(ketebalan-(toleransi/10)) as mintebal FROM tb_coring, tb_coredrill WHERE tb_coring.kode_material='$material' and tb_coring.kode_proyek='$proyek' and tb_coredrill.kode_material='$material' and tb_coredrill.kode_proyek='$proyek' and tb_coring.tanggal_coring='$tgl' GROUP BY tanggal_coring";           
}
$hasil=mysqli_query($db,$sql);
$no=0;
while ($data = mysqli_fetch_array($hasil)) {
    ?>
    <tr>
        <td>Jumlah Data : <?php echo $data['mintebal'];   ?></td>                
    </tr>            
<?php
}

example i have 10 if i only echo mintebal but it will echo 8 data that fit the condition or should i just add more column for the result of the formula on my database for easier count?

  • 1
    Since you have no `GROUP BY`, `COUNT(*)` aggregates all the results into a single row. And all the other columns come from random rows that match the `WHERE` conditions. – Barmar Dec 27 '22 at 08:02
  • 2
    You're probably getting an `ONLY_FULL_GROUP_BY` error because you're aggregating and also trying to return columns from the table. See https://stackoverflow.com/questions/34115174/error-related-to-only-full-group-by-when-executing-a-query-in-mysql – Barmar Dec 27 '22 at 08:03

0 Answers0