<?
$sql = dbquery("SELECT `id`, `title`, `description` FROM `content` LIMIT 0,12 ");
while ($row = mysql_fetch_array($sql)) {
$id = $row["id"];
$title = $row["title"];
$description = $row["description"];
$content = '
<div class="description-box">
<p>page id: ' . $id . '</p>
<p>' . $title . '</p>
<p>' . $description . '</p>
</div>';
}
echo $content;
?>
//聲明:DIV CLASS = 「描述盒」我該如何解決這個PHP的MySQL循環?
//我怎麼能替換成:DIV CLASS = 「描述盒nopadding」 每3周輸出的div後? HTML的
例生成的代碼:
<div class="description-box nopadding">
// content
</div>
<div class="description-box">
// content
</div>
<div class="description-box">
// content
</div>
<div class="description-box">
// content
</div>
//然後再分度nopadding
使用計數器變量,由3每次的循環是時間把它和如果整數除法的其餘部分是0 - 你有「每隔3次」迭代。 –
它可能無助於回答你的問題,但你應該停止使用'mysql_ *'函數。他們正在被棄用。請使用[PDO](http://php.net/manual/en/book.pdo.php)(自PHP 5.1起支持)或[mysqli](http://php.net/manual/en/book)。 mysqli.php)(自PHP 4.1起支持)。如果你不確定使用哪一個,[閱讀本文](http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/)。 – Matt
你也應該避免使用像這樣的短開標籤(' ?>')。 ''不是很多額外的工作,即使你必須在頁面上輸入10次,它也可以確保你的服務器支持代碼。 '= ?>'是一個不同的故事,無論您的服務器上是否啓用了'short_open_tags',它仍然有效(從PHP 5.4開始)。 – Matt