【发布时间】:2017-02-23 14:47:20
【问题描述】:
如何计算来自 MySQL 的重复“itemid”条目。下面的代码在 MySQL 中导出结果,但我想计算每个重复“itemid”的总数。
示例: 输出(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");
}
【问题讨论】:
-
提示:
GROUP BY. -
绝对是stackoverflow.com/q/688549/3664960 的副本,那里有很多答案和很多赞成
-
我已经尝试了链接,但我无法修复它,因此我已经问过了。