2011-05-28 59 views
0

这里就是我想实现:enter image description here 我使用的mysqli客观。需要帮助的显示数据库内容

我连接到数据库:

<?php 
$mysqli= new mysqli( 
'xxxxx', #host 
'xxxxx', #username 
'xxxxx', #password 
'xxxxx'); #database name 

if ($mysqli->connect_error) 
{ 
die("Connect Error: $mysqli->connect_error"); 
} 
?> 

我有一个自动递增的ID字段,“标题”字段,“说明”字段和包含URL的图像,所以我可以一个字段使用

<img src="<url from database>" alt="<title from database>" /> 

我需要把它格式化方式与图片一样,我被困在如何使每一行被格式化这样就形成了将艺术品的投资组合对数据进行分离。

这样做了学校的项目,因此任何帮助是极大的赞赏。

回答

1
$result = $mysqli->query('SELECT title, description, image FROM table;'); 

while($o = $result->fetch_object()) { 
    echo '<div class="image">'; 
    echo '<img src="', htmlspecialchars($o->image),'" alt="', htmlspecialchars($o->title),'" />'; 
    echo '<h3>', htmlspecialchars($o->title), '</h3>'; 
    echo '<p>', htmlspecialchars($o->description), '</p>'; 
    echo '</div>'; 
} 
+0

完美,太谢谢你了。 – Callum 2011-05-28 05:57:14