【发布时间】:2015-05-08 14:08:43
【问题描述】:
我有一个存储项目信息的数据库,包括图像源路径、描述等。目前数据是静态的,如下面的代码 sn-p 所示。基本上我需要为表中的每一行数据输出一个新的“缩略图”。我认为这是由 for 循环完成的,但是我不确定如何实现这一点。谢谢。
<div class='panel-heading' contenteditable='false'>Your items for sale</div>
<div class='panel-body'>
<div class='row'>
<div class='col-md-4'>
<div class='thumbnail'>
<img alt='300x200' src='http://lorempixel.com/600/200/people'>
<div class='caption'>
<h3>
Rover
</h3>
<p>Cocker Spaniel who loves treats.</p>
<p></p>
</div>
</div>
</div>
<div class='col-md-4'>
<div class='thumbnail'>
<img alt='300x200' src='http://lorempixel.com/600/200/city'>
<div class='caption'>
<h3>
Marmaduke
</h3>
<p>Is just another friendly dog.</p>
<p></p>
</div>
</div>
</div>
<div class='col-md-4'>
<div class='thumbnail'>
<img alt='300x200' src='http://lorempixel.com/600/200/sports'>
<div class='caption'>
<h3>
Rocky
</h3>
<p>Loves catnip and naps. Not fond of children.</p>
<p></p>
</div>
</div>
</div>
</div>
</div>
我的尝试:
<? $sql = "SELECT srcpath FROM images";
$res = mysql_query($sql) or die(mysql_error());
$result = mysql_query($sql);
echo '<div"><ul>';
while ($fetch = mysql_fetch_array($result)) {
$petname = $fetch['username'];
echo '<li><P>'.$fetch['description'].'</P>';
echo '<img src="'.$fetch['srcpath'].'" alt="" />';
echo '</li>';
}
echo '</ul></div>';
?>
【问题讨论】:
-
我认为人们在给出答案之前会想看看你的镜头。您是否找到任何教程或您尝试遵循的任何内容?您尝试过任何 PHP 代码吗?
-
抱歉,你是对的。我已经在一定程度上进行了尝试,并将添加到主帖中。
-
您是否遇到了某种错误?如我所见,您的查询中不存在“用户名”和“描述”字段,
-
请stop using
mysql_*functions。它们不再被维护并且是officially deprecated。改为了解 prepared statements,并考虑使用 PDO,it's not as hard as you think。 -
@JayBlanchard ^ 也可以被忽略 Sam。但是,不是 moi ;-)