我如何制作幻灯片,从数据库中获取网站php,html和css的信息(图像,标题,内容)?
我想为标题网站上的最后十个帖子(产品)或功能帖子(产品)制作幻灯片。怎么能做到这一点?感谢。
所以这个脚本幻灯片显示,我想从表格中替换来自数据库的源(图像,标题,描述)。
<a href="#" class="show">
<img src="images/flowing-rock.jpg" alt="Flowing Rock" width="580" height="360" title="" alt="" rel="<h3>Flowing Rock</h3>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "/>
</a>
<a href="#">
<img src="images/grass-blades.jpg" alt="Grass Blades" width="580" height="360" title="" alt="" rel="<h3>Grass Blades</h3>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "/>
</a>
<a href="#">
<img src="images/ladybug.jpg" alt="Ladybug" width="580" height="360" title="" alt="" rel="<h3>Ladybug</h3>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."/>
</a>
<a href="#">
<img src="images/lightning.jpg" alt="Lightning" width="580" height="360" title="" alt="" rel="<h3>Lightning</h3>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."/>
</a>
<a href="#">
<img src="images/lotus.jpg" alt="Lotus" width="580" height="360" title="" alt="" rel="<h3>Lotus</h3>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo."/>
</a>
<a href="#">
<img src="images/mojave.jpg" alt="Mojave" width="580" height="360" title="" alt="" rel="<h3>Mojave</h3>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt."/>
</a>
<a href="#">
<img src="images/pier.jpg" alt="Pier" width="580" height="360" title="" alt="" rel="<h3>Pier</h3>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."/>
</a>
<a href="#">
<img src="images/sea-mist.jpg" alt="Sea Mist" width="580" height="360" title="" alt="" rel="<h3>Sea Mist</h3>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."/>
</a>
<a href="#">
<img src="images/stones.jpg" alt="Stone" width="580" height="360" title="" alt="" rel="<h3>Stone</h3>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."/>
</a>
我想要post indeasted链接图像,代码php从数据库中获取图像,以及标题和内容,但我想make(do {wile())},只获得最后十个产品。 `
答案 0 :(得分:2)
好吧,您还没有提供有关数据库结构的任何详细信息......但是我们将介绍基础知识......
首先,您需要执行一个返回10个项目(作为数组)的数组的查询。然后你需要创建一个输出所有内容的循环......
在MySQLi中,你会做这样的事情......
$objStmt = $this->objDb->prepare("
SELECT image, imageAlt, imageTitle, imageRel FROM posts WHERE [some criteria is met];
");
$objStmt->bind_param([some params to bind]);
$objStmt->execute();
$objStmt->bind_result($image, $imageAlt, $imageTitle, $imageRel);
$arrItems = array();
while ($objRow = $objStmt->fetch()) {
$arrItem = array();
$arrItem['image'] = $image;
$arrItem['imageAlt'] = $imageAlt;
$arrItem['imageTitle'] = $imageTitle;
$arrItem['imageRel'] = $imageRel;
array_push($arrItems, $arrItem);
unset($arrItem);
}
然后......
foreach ($arrItems as $arrItem) {
printf('<a href="#" class="show"><img src="%s" alt="%s" width="580" height="360" title="%s" alt="" rel="%s"/></a>', $arrItem['image'], $arrItem['imageAlt'], $arrItem['imageTitle'], $arrItem['imageRel']);
}