gpt4 book ai didi

php - 从 MySQL 数据库引导照片库

转载 作者:行者123 更新时间:2023-11-28 07:06:30 25 4
gpt4 key购买 nike

编程新手,刚刚完成我的网站开发类(class)的一半,所以希望我的问题不会太愚蠢。我想显示 4 个来自 MySQL 数据库的随机图像(图像存储在上传文件夹中),代码如下。它工作正常,但使用 Bootstrap 布置图库代码时不再在页面上显示图像。提前感谢任何帮助

<?php
require 'includes/dbconnection.php';
$sql = "SELECT * from uploads ORDER BY RAND () LIMIT 4";
$result=mysqli_query($conn, $sql) or die ('Problem: '.$sql)."<br>";
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/custom.css">
<title>Pete's fishing adventures</title>
</head>

<body>
<!-- header and navigation -->
<?php include 'includes/header.php'; ?>

<div class="container">
<!-- body text -->
<header>
<h3>Celebrating the ones that got away and the ones that didnt</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab libero, cupiditate veniam officiis itaque in porro iure fugit iusto reprehenderit commodi earum cum blanditiis quos error similique quod, facere! Hic.</p>
</header>

<!-- Featured carousel -->
<div class="carousel slide col-lg-8 col-lg-offset-2 col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1 col-xs-10 col-xs-offset-1" data-ride="carousel" id="featured">
<div class="carousel-inner">
<div class="item active"><img class="img-responsive center-block" src="images/carousel1.jpg" alt="carousel1"></div>
<div class="item"><img class="img-responsive center-block" src="images/carousel2.jpg" alt="carousel2"></div>
<div class="item"><img class="img-responsive center-block" src="images/carousel3.jpg" alt="carousel3"></div>
<div class="item"><img class="img-responsive center-block" src="images/carousel4.jpg" alt="carousel4"></div>
<div class="item"><img class="img-responsive center-block" src="images/carousel5.jpg" alt="carousel5"></div>
</div> <!-- carousel inner -->
<a class="left carousel-control" href="#featured" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="right carousel-control" href="#featured" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div> <!-- featured carousel -->

<div class="clearfix">
</div>

<!-- photo gallery -->
<div class="row">
<?php
if (mysqli_num_rows($result)) {
while ($row = mysqli_fetch_array($result)) { ?>
<div class="col-xs-3"> <!-- gallery images -->
<a class="thumbnail" href="#">
<img src="uploads/<?php echo $row['image_name'];?> " />
<div class="caption">
<h4>Gallery 1</h4>
<p>Some text about the photo.</p>
</div>
</a>
</div> <!-- end gallery image-->
<?php
} /* end of while statement */
} /* end if (mysqli_num_rows($result)) */
?>
</div> <!-- end $row -->
<!-- end of photo gallery -->

<?php
} /* end of while statement */
} /* end if (mysqli_num_rows($result)) */
?>
<!-- end of photo gallery -->

<!-- body text -->
<section>
<h2>Headline</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab libero, cupiditate veniam officiis itaque in porro iure fugit iusto reprehenderit commodi earum cum blanditiis quos error similique quod, facere! Hic.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab libero, cupiditate veniam officiis itaque in porro iure fugit iusto reprehenderit commodi earum cum blanditiis quos error similique quod, facere! Hic.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab libero, cupiditate veniam officiis itaque in porro iure fugit iusto reprehenderit commodi earum cum blanditiis quos error similique quod, facere! Hic.</p>
</section>
</div> <!-- end container -->

<!-- Footer -->
<?php include 'includes/footer.php' ?>

<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>

最佳答案

因为我认为您正在为每张照片创建一个厨房,而不是为所有照片创建一个厨房。

我认为你应该...

<div class="row">
<div class="col-xs-3"> <!-- gallery images -->
<?php
if (mysqli_num_rows($result)) {
while ($row = mysqli_fetch_array($result)) { ?>
<a class="thumbnail" href="#">
<img class="img-responsive" src="uploads/<?php echo $row['image_name'];?> " >
<div class="caption">
<h4>Gallery 1</h4>
<p>Some text about the photo.</p>
</div>
</a>
<!-- end gallery image-->
<?php
} /* end of while statement */
} /* end if (mysqli_num_rows($result)) */
?>
</div>
</div> <!-- end photo gallery -->

所以...首先创建一个新行。然后在其中创建一个画廊。然后开始循环以填充图库

关于php - 从 MySQL 数据库引导照片库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32919675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com