Wie zähle ich doppelte "itemid" -Einträge von MySQL? Der Code unterhalb der Exporte führt zu MySQL, aber ich möchte die Summe jedes Duplikats "itemid" zählen. Beispiel: Ausgabe (122,133,122,122,133,188). 122 = 3, 133 = 2, 188 = 1.Wie zählt man die Summe aller doppelten Werte von MySQL in PHP?
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");
}
Hinweis: 'GROUP BY'. –
Mögliches Duplikat von [Doppelte Werte in MySQL finden] (http://stackoverflow.com/questions/688549/finding-duplicate-values-in-mysql) – davejal
Definitiv ein Duplikat von http://stackoverflow.com/q/688549/3664960, so viele Antworten dort mit vielen upvotes – davejal