数据库截图
查询:
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
$qry = "SELECT `image` FROM product_images WHERE product_id = '".$id."';";
$res = mysqli_query($conn,$qry);
$row = mysqli_fetch_assoc($res);
问题:
我想在浏览器中显示所有图片名称。怎么可能呢?
答案 0 :(得分:0)
试试这个:
<?php
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
$qry = 'SELECT image FROM product_images WHERE product_id = \'' . $conn->real_escape_string($id) . '\'';
$res = mysqli_query($qry, $conn);
while($row = mysqli_fetch_assoc($res))
echo $row . '<br />' . "\n";
}
答案 1 :(得分:-1)
<?php
// absolute or relative path
$base_path = 'http://domain.com/uploads/';
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
$qry = "SELECT image FROM product_images WHERE product_id = '".$id."'";
$res = mysqli_query($conn,$qry);
if (mysqli_num_rows($res) > 0)
{
while ($row = mysqli_fetch_assoc($res))
{
$image_name = $row['image'];
$image_path = $base_path.$image_name;
// To display image name
echo 'Image name = '.$image_name.'<br />';
//To display image
echo '<img src="'.$image_path.'" width="" height="" alt="" title="" />';
}
}
?>