如何显示存储在我的数据库中的所有图像?

时间:2017-01-09 07:37:42

标签: php mysql

这是我的示例代码请帮帮我们

<?php
$con =mysql_connect("localhost", "" , "");
$sdb= mysql_select_db("image",$con);
$sql = "SELECT * FROM `tbl_image` WHERE id=21";
$mq = mysql_query($sql) or die ("not working query");
$row = mysql_fetch_array($mq) or die("line 44 not working");
$s = $row['img_url'];
echo '<img src="'.$s.'">';
?>

4 个答案:

答案 0 :(得分:0)

循环行。

$mq = mysql_query($sql) or die ("not working query");

while ($row = mysql_fetch_array($mq)) {
    echo '<img src="' . $row['img_url'] . '" >';
}

答案 1 :(得分:0)

应该将最后两行更改为此

while ($row = mysql_fetch_assoc($result)) {
    $s = $row['img_url'];
    echo '<img src="'.$s.'">';
}

答案 2 :(得分:0)

<?php
$con = mysql_connect("localhost", "" , "");
$sdb = mysql_select_db("image",$con);
$sql = "SELECT * FROM `tbl_image` WHERE id=21";
//echo "SELECT * FROM `tbl_image` WHERE id=21";  //and run the query in database if it is working fine then you can use while loop.

$mq  = mysql_query($sql) or die ("not working query"); // if this line is not working try eho the above query like i have mentioned in comments.

     while ( $row = mysql_fetch_array($mq)) {
          echo '<img src="' . $row['img_url'] . '" >';
     }   
 ?>

答案 3 :(得分:-1)

您可以尝试以下代码。

 while($row=mysql_fetch_object($qry))
{
    $result[] = $row['img_url'];
echo '<img src="' . $row['img_url'] . '" >';
}

print_r($result)