本文介紹了每三個 div 的 php while 循環變量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
是他們在 while 循環中將變量分配給 div 中的類的一種方式,對于 while 循環中的每三個項目.我正在使用藍圖結構,第三個 div 在最后,我需要為每三個 div 附加一個最后一個"類名,所以 3rd div 6th div 9th div 等等?
/* 循環鞋數據表 */$results = mysql_query("SELECT * FROM shoesData");while($row = mysql_fetch_array($results)){$name = $row['name'];$about = $row['about'];$company = $row['company'];$buy = $row['buy'];$tags = $row['tags'];$id = $row['id'];$image = $row['image'];/* 回顯鞋數據結果 */echo "";echo "<div id='imageHeight'>";echo "<img src='thumbs/$image'>";回聲</div>";echo "";echo "- $name";echo "<li>$about</l1>";echo "<li>$company</l1>";echo "<li><a href='$buy'>BUY</a></l1>";echo "<li>$tags</l1>";echo "</ul>";回聲</div>";}/*當循環結束時鞋數據*/ 解決方案
for ($i = 0; $i <$numRecords; $i++){$className = "";如果 (($i % 3) == 0){$className = "last"}....}
這里的關鍵部分是($i % 3) == 0
.
以下是對您的評論的回應.
/* 循環鞋數據表 */$results = mysql_query("SELECT * FROM shoesData");$i = 0;while($row = mysql_fetch_array($results)){$i++;$name = $row['name'];$about = $row['about'];$company = $row['company'];$buy = $row['buy'];$tags = $row['tags'];$id = $row['id'];$image = $row['image'];/* 回顯鞋數據結果 */$additionalClass = ($i % 3) == 0 ?"最后的" : "";echo "<div class='imageBorder span-8 column" .$additionalClass ."'>";echo "<div id='imageHeight'>";echo "<img src='thumbs/$image'>";回聲</div>";echo "";echo "- $name";echo "<li>$about</l1>";echo "<li>$company</l1>";echo "<li><a href='$buy'>BUY</a></l1>";echo "<li>$tags</l1>";echo "</ul>";回聲</div>";}/*當循環結束時鞋數據*/
Is their a way in a while loop to assign a variable to a class in a div, for every third item in a while loop. I am using the blueprint structure and the third div is at the end and i need to attacht a "last" class name to every third div so 3rd div 6th div 9th div and so on?
/* LOOP THROUGH SHOEDATA TABLE */
$results = mysql_query("SELECT * FROM shoeData");
while($row = mysql_fetch_array($results)){
$name = $row['name'];
$about = $row['about'];
$company = $row['company'];
$buy = $row['buy'];
$tags = $row['tags'];
$id = $row['id'];
$image = $row['image'];
/* ECHO THE SHOEDATA RESULTS */
echo "<div class='imageBorder span-8 column'>";
echo "<div id='imageHeight'>";
echo "<img src='thumbs/$image'>";
echo "</div>";
echo "<ul>";
echo "<li>$name</l1>";
echo "<li>$about</l1>";
echo "<li>$company</l1>";
echo "<li><a href='$buy'>BUY</a></l1>";
echo "<li>$tags</l1>";
echo "</ul>";
echo "</div>";
}/*SHOEDATA WHILE LOOP ENDS */
解決方案 for ($i = 0; $i < $numRecords; $i++)
{
$className = "";
if (($i % 3) == 0)
{
$className = "last"
}
....
}
The key part here is the ($i % 3) == 0
.
EDIT: The following is in response to your comment.
/* LOOP THROUGH SHOEDATA TABLE */
$results = mysql_query("SELECT * FROM shoeData");
$i = 0;
while($row = mysql_fetch_array($results)){
$i++;
$name = $row['name'];
$about = $row['about'];
$company = $row['company'];
$buy = $row['buy'];
$tags = $row['tags'];
$id = $row['id'];
$image = $row['image'];
/* ECHO THE SHOEDATA RESULTS */
$additionalClass = ($i % 3) == 0 ? " last" : "";
echo "<div class='imageBorder span-8 column" . $additionalClass . "'>";
echo "<div id='imageHeight'>";
echo "<img src='thumbs/$image'>";
echo "</div>";
echo "<ul>";
echo "<li>$name</l1>";
echo "<li>$about</l1>";
echo "<li>$company</l1>";
echo "<li><a href='$buy'>BUY</a></l1>";
echo "<li>$tags</l1>";
echo "</ul>";
echo "</div>";
}/*SHOEDATA WHILE LOOP ENDS */
這篇關于每三個 div 的 php while 循環變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!