我已經構建了一個SQL查詢來佈置一些網頁上的信息。查詢運作良好。問題是與while循環CSS類必須是自動遞增每次迭代由1需要想法正確的HTML呈現與PHP
<div class="related-item item1">
「物品1」應該成爲「ITEM2」在接下來的迭代等等。你能給我一些想法如何去做嗎?
<?php
//Construct the SQL query code
$rel = "SELECT entries.*, images.name
FROM entries, images
WHERE entries.id = blog_id
ORDER BY dateposted DESC
LIMIT 0, 3;";
//Send the query to the MySQL server
$result = mysql_query($rel);
//Pull the row as an associative array
while ($row = mysql_fetch_assoc($result)) {
echo '<div class="related-item item1">
<div class="thumbnail-wrapper">';
echo '<a href="#"><img src="./images/' . $row['name'] . '" alt="How SHAPE Reader Caitlin Flora Lost 182 Pounds"/></a></div>
<h4 class="related-article-title">
<a href="#">' . $row['subject'] . '</a>
</h4>
</div>';
} //End of while loop
?>
請,或不使用新代碼'mysql_ *'功能(http://stackoverflow.com/questions/12859942/why-不應該-I-使用MySQL的函數式的PHP)。 *他們不再維護,並[已正式棄用](https://wiki.php.net/rfc/mysql_deprecation)*。看到[紅色框](http://uk.php.net/manual/en/function.mysql-connect.php)?學習[準備的語句](http://en.wikipedia.org/wiki/Prepared_statement),並使用[PDO](http://us1.php.net/pdo)或[MySQLi](http:// us1.php.net/mysqli)。 [這篇文章](http://php.net/manual/en/mysqlinfo.api.choosing.php)將幫助你決定哪些。 – 2014-10-01 19:52:32