How do I count duplicate "itemid" entries from MySQL. The code below exports results in MySQL, but I want to count the total of each duplicate "itemid".
Example: output(122,133,122,122,133,188). 122=3, 133=2, 188=1.
if(isset($_POST['daily']) && isset($_POST['reportdate'])){
global $conn;
$date = $_POST['reportdate'];
$sql = $conn->prepare("SELECT * FROM issues WHERE date='$date'");
$sql->execute();
$output .='
<table class="table" bordered="1">
<tr>
<th class="green">SAPCODE</th>
<th class="green">DATE</th>
<th class="green">DESCRIPTION</th>
<th class="green">QUANTITY</th>
<th class="green">UNIT</th>
<th class="green">ISSUED TO</th>
</tr>
';
while($row = $sql->fetch(PDO::FETCH_ASSOC)){
$perstat->getID($row['empid']);
$stock->getItemByID($row['itemid']);
$time = strtotime($row['date']);
$row['date']= date("d-M-y", $time);
$output .='
<tr>
<td>'.$row['itemid'].'</td>
<td>'.$row["date"].'</td>
<td>'.$stock->description.'</td>
<td>'.$row["qty"].'</td>
<td>'.$stock->unit.'</td>
<td>'.$perstat->pats.'</td>
</tr>
';
}
$output .='</table>';
header("Content-Type: application/xls");
header("Content-Disposition:attachment; filename=PPE Issuance report .xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $output;
}else{
header("Location:issuelist.php");
}