我正在尝试将数据库中的图像显示到bootstrap div,这是我的代码:
$sql = "SELECT * FROM berita ORDER BY id DESC LIMIT 0, 1";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$image= $row['gambar'];
$title = $row['judul'];
$description = $row['konten'];
$time = $row['tanggal'];
echo"<html>";
echo"<head>";
echo"<title>Business_Blog | Home </title>";
echo"<meta name='viewport' content='width=device-width, initial-scale=1'>";
echo"<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
echo"<meta name='keywords' content='Business_Blog Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template,
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design' />";
echo "<script type='applijewelleryion/x-javascript'> addEventListener('load', function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>";
echo "<link href='css/bootstrap.css' rel='stylesheet' type='text/css' />";
//<!-- Custom Theme files -->
echo "<link href='//fonts.googleapis.com/css?family=Roboto+Condensed:400,700' rel='stylesheet' type='text/css'>";
echo "<link href='//fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>";
echo "<link href='css/style.css' rel='stylesheet' type='text/css' />";
echo "<script src='js/jquery-1.11.1.min.js'></script>";
echo "<script src='js/bootstrap.min.js'></script>";
echo" </head>";
echo" <div class='tc-ch'>";
echo" <div class='tch-img'>";
echo" <a href='singlepage.html'><img src='images/$image' class='img-responsive' alt=''/></a>";
echo "</div>";
echo" <a class='blog blue' href='singlepage.html'> Technology</a>";
echo" <h3><a href='singlepage.html'>$title</a></h3>";
echo" <p>".substr($description,0,200)."<a href=articles.php?id=".$row['id']." > Read more</a></p>";
echo" <div class='blog-poast-info'>";
echo" <ul>";
echo" <li> <i class='glyphicon glyphicon-user'> </i><a class='admin' href='#'>Admin </a><li>";
echo" <li> <i class='glyphicon glyphicon-calendar'> </i>$time</li>";
echo" <li> <i class='glyphicon glyphicon-comment'> </i><a class='p-blog' href='#'>3 comments</a></li>";
echo" <li> <i class='glyphicon glyphicon-heart'> </i><a class='admin' href='#'>5 favourites</a></li>";
echo" <li> <i class='glyphicon glyphicon-eye-open'> </i>1.128</li>";
echo" </ul>";
echo" </div> ";
echo" </div>";
echo" <div class='clearfix'></div>";
//<!-- technology-top -->
//<!-- technology-top -->
echo" <div class='soci'>";
echo" <ul>";
echo" <li><a href='#' class='facebook-1'> </a></li>";
echo" <li><a href='#' class='facebook-1 twitter'> </a></li>";
echo" <li><a href='#' class='facebook-1chrome'> </a></li>";
echo" <li><a href='#'><i class='glyphicon glyphicon-envelope'> </i></a></li>";
echo" <li><a href='#'><i class='glyphicon glyphicon-print'> </i></a></li>";
echo" <li><a href='#'><i class='glyphicon glyphicon-plus'> </i></a></li>";
echo" </ul>";
echo" </div>";
//echo "<img src=".$row['gambar']." />";
//echo "<p>".substr($row['konten'],0,200)."<a href=articles.php?id=".$row['id']." > Read more</a></p>";
echo"</html>";
}
$conn->close();
?>
其他所有代码都运行正常,但是当我回显$image
时它不起作用,但是当我使用html代码时它工作<a href="singlepage.html"><img src="images/1.jpg" class="img-responsive" alt=""/></a>
。图像成功插入数据库,我回应了bootsrap css和其他文件,但它不起作用,我也没有得到错误消息。请任何帮助将不胜感激。
答案 0 :(得分:2)
强烈建议不要在数据库中保存照片,因为数据类型将更改为blob,您必须在插入和拉动时调整类型,而是可以将照片保存在文件夹中并将路径保存在数据库中作为字符串。 希望这会有所帮助。