按排序结果
series_id,因此所有具有相同值的产品将在一起。
$stmt = $pdo->prepare("SELECt series_id, product_name FROM yourTable ORDER BY series_id");$stmt->execute();然后在显示结果时,显示Series标头,并
<ul>在更改时开始新的标头:
$last_series = null;echo "<ul>n";while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { if ($row['series_id'] != $last_series) { if ($last_series) { echo "</ul></li>n"; } echo "<li>" . $row['series_id'] . " Series Productn"; echo "<ul>n"; $last_series = $row['series_id']; } echo "<li>" . $row['product_name'] . "</li>n";}if ($last_series) { echo "</li>n";}echo "</ul>n";

![如何在PHP中使用while循环列出具有相同ID的数据?[关闭] 如何在PHP中使用while循环列出具有相同ID的数据?[关闭]](http://www.mshxw.com/aiimages/31/400647.png)
