我正在尝试编写一个查询,其中将从具有相同列名的数据库的表列中获取图像。 这是我的代码:
<?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>';
}
?>
但是在这个脚本中我一次又一次地得到相同的图像。 任何帮助 预先感谢您。
最佳答案
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>';
}
?>
关于php - 从数据库中获取相同列名的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38324525/