0

I have written code to search data. But when I am running code it's not showing any error and not fetching any data. Could anyone please help me to find out the problem?

HERE IS MY CODE

<?php 
    $db = new PDO('mysql:dbname=mypro_bms;host=localhost', 'root', '');
    $people = [];
    if (!empty($_GET['p'])) {

        $count='count';
        $sum='sum';
        $stmt=$db->prepare("SELECT passport_IC,count(*) as count,sum(blood_bag) as sum  FROM donate GROUP BY passport_IC where passport_IC like :passport_IC");
        $stmt->execute([
        ':passport_IC' => '%' . $_GET['p'] .'%',
        ':count'=> $count,
        ':sum' => $sum,
        ]);  


        $people = $stmt->fetchAll(PDO::FETCH_OBJ);
    }
?> 
    <table class="table table-bordered">
        <tr>
            <th><center> passport </center></th>
            <th><center> Donation Completed</center></th>
            <th>blood donated</th>
            <th><center> Percentage</center></th>
        </tr>
<?php foreach($people as $donors): ?>
        <tr>
            <td><center><b><font color="black"><?= $donors->passport_IC; ?></font></b></center></td>
            <td><center><b><font color="black"><?= $donors->count; ?>*Times*</font></b></center></td>
            <td><center><b><font color="black"><?= $donors->sum; ?>ml</font></b></center></td>
        </tr>
<?php endforeach; ?>
    </table>
PrakashG
  • 1,642
  • 5
  • 20
  • 30
Mim Hsan
  • 17
  • 4
  • Did you run the query on mysql console, To check if the query fetching you data. – Rahul Singh Apr 11 '19 at 07:31
  • `Not showing any error` - That is because you don't [check for any errors](https://stackoverflow.com/questions/8776344/how-to-view-query-error-in-pdo-php) in your code. – DarkBee Apr 11 '19 at 08:13

1 Answers1

0

Your query is wrong. Group by should be after where clause.

SELECT passport_IC,count(*) as count,sum(blood_bag) as sum  FROM donate where passport_IC like :passport_IC GROUP BY passport_IC
Rahul Singh
  • 918
  • 14
  • 31