我如何列出与PHP中的while循环相同的id数据?

我有一个MySQL表。 这样的列

series_id, series_color, product_name 

我应该列出与group一样的series_id product

我想要那个列表所有相同的sary_id回显我的屏幕

 A12 Series Product - Milk - Tea - sugar - water B12 Series Product - Water - Banana - Cofee - Tea 

通过series_id订购你的结果,所有具有相同价值的产品将会在一起。

 $stmt = $pdo->prepare("SELECT series_id, product_name FROM yourTable ORDER BY series_id"); $stmt->execute(); 

然后当显示结果时,显示系列标题,并<ul>更改一个新的<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 Product\n"; echo "<ul>\n"; $last_series = $row['series_id']; } echo "<li>" . $row['product_name'] . "</li>\n"; } if ($last_series) { echo "</li>\n"; } echo "</ul>\n";