我创建了基于产品搜索返回图像名称和 ID 的函数。我想显示所有图像,但我希望每张图像都有不同的样式。我想有一种方法可以增加 div id 但不确定。这是我的函数和调用:
public function getImages($searchterm=""){
$sql = "SELECT id FROM prod_detail
WHERE prod_detail.int_prod_code LIKE '$searchterm' ORDER BY `id` ASC";
$stmt = mysqli_query($this->connection, $sql)or die(mysqli_error($this->connection));
while($result = mysqli_fetch_array($stmt)){
$sql2="SELECT image_name FROM images WHERE image_ref={$result['id']}";
$stmt2 = mysqli_query($this->connection, $sql2)or die(mysqli_error($this->connection));
$num_rows = mysqli_num_rows($stmt2);
while($result2 = $stmt2->fetch_assoc()){
foreach ($result2 as $key => $value) {
$returns = $this->dir . $value;
}
}
}
return $returns;
}
这是显示图像的函数调用
foreach($newProd->getAllProductSpec($searchterm) as $item => $val){
echo "<img src='server/php/files/{$val['image_name']}'
alt='Flying screens' style='float:left;margin:0 30px 20px 0'/>"; ?>
}