我正在尝试编写一个查询,其中的图像将从同一列名的数据库的表列中获取。 这是我的代码:
<?php
$connect=new mysqli("localhost","root","") or die(mysqli_connect_error());
mysqli_select_db($connect,'go-web') or die(mysqli_connect_error());
$query=mysqli_query($connect,"SELECT * from product where name like 'Groc%'");
while($row=mysqli_fetch_array($query)){
$sql="SELECT image from product where name like 'Groc%'";
$query1=mysqli_query($connect,$sql);
$dff=mysqli_fetch_row($query1);
$image=$dff[0];
echo '<td style="border: 1px solid black;height:100px"><img src="'.$image.'" width="150px" height="150px" /><center><figcaption>Price:</figcaption></center><br> <center><figcaption>Stock:</figcaption></center></td>';
}
?>
但是在这个剧本中,我一次又一次地得到同样的图像。 任何帮助 提前谢谢。
答案 0 :(得分:0)
1)*从表中获取所有列,因此不需要第二次选择查询。
试试这个
<?php
$connect=new mysqli("localhost","root","") or die(mysqli_connect_error());
mysqli_select_db($connect,'go-web') or die(mysqli_connect_error());
$query=mysqli_query($connect,"SELECT * from product where name like 'Groc%'");
while($row=mysqli_fetch_array($query))
{
// $sql="SELECT image from product where name like 'Groc%'";
// $query1=mysqli_query($connect,$sql);
// $dff=mysqli_fetch_row($query1);
// $image=$dff[0];
echo '<td style="border: 1px solid black;height:100px"><img src="'.$row['image'].'" width="150px" height="150px" /><center><figcaption>Price:</figcaption></center><br> <center><figcaption>Stock:</figcaption></center></td>';
}
?>