Data
+----+---------+----------+-----------+---------------------+
| id | refno | agent_id | status_to | logtime |
+----+---------+----------+-----------+---------------------+
| 1 | LP01552 | 57 | Draft | 2021-10-05 10:33:12 |
| 2 | LP02552 | 57 | Unpublish | 2021-10-04 10:33:12 |
| 3 | LP03552 | 57 | Draft | 2021-10-05 10:33:12 |
| 4 | LP04552 | 57 | Publish | 2021-10-09 10:33:12 |
| 5 | LP05552 | 57 | Draft | 2021-10-10 10:33:12 |
| 6 | LP06552 | 57 | Publish | 2021-10-11 10:33:12 |
| 7 | LP07552 | 57 | Action | 2021-10-06 10:33:12 |
| 8 | LP08552 | 58 | Draft | 2021-10-02 10:33:12 |
| 9 | LP09552 | 58 | Unpublish | 2021-10-11 10:33:12 |
| 10 | LP09652 | 58 | Publish | 2021-10-08 10:33:12 |
| 11 | LP08542 | 59 | Draft | 2021-10-06 10:33:12 |
| 12 | LP09542 | 59 | Unpublish | 2021-10-06 10:33:12 |
| 13 | LP09642 | 59 | Draft | 2021-10-07 10:33:12 |
+----+---------+----------+-----------+---------------------+
Code
<?php
$res = $db->prepare("SELECT
agent_id as Agent
, SUM(status_to = 'Draft') as Draft
, SUM(status_to = 'Unpublish') as Unpublish
, SUM(status_to = 'Publish') as Publish
, SUM(status_to = 'Action') as Action
FROM crm_log
WHERE logtime BETWEEN ? AND ?
GROUP BY agent_id
");
$res->execute( [ '2021-10-01', '2021-10-31' ] );
$data = '';
$row = $res->fetch();
$heads = "<tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>\n";
do {
$data .= "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n";
} while ($row = $res->fetch());
?>
<table border='1' style='border-collapse: collapse; width: 500px'>
<?=$heads?>
<?=$data?>
</table>
Output