2011-05-28 60 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