我有一张图片表,我需要列出产品的所有图片才能连续显示:
我有这个问题:
<?php
require_once 'assets/files/meekrodb.php';
$results = DB::query("SELECT * FROM images");
foreach ($results as $row) {
echo $row['imagen'] . "<br>";
}
?>
向我展示了这一点:
你能帮助我吗,提前谢谢!
答案 0 :(得分:3)
您可以在获取结果时按产品分组:
$results = DB::query("SELECT * FROM images");
foreach ($results as $row) {
// use product as key, add image to array at that key
$products[$row['product']][] = $row['imagen'];
}
然后输出这样的组:
foreach ($products as $product => $images) {
echo implode(', ', $images) . '<br>';
}