每个第三个div的php while循环变量

前端之家收集整理的这篇文章主要介绍了每个第三个div的php while循环变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
它们是while循环中的一种方式,可以为div中的类分配变量,用于while循环中的每个第三项.我正在使用蓝图结构,第三个div在最后,我需要为每个第三个div附加一个“最后”类名,所以第3个div第6个div第9个div等等?
/* 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"
 }

 ....
}

这里的关键部分是($i%3)== 0.

编辑:以下是对您的评论的回应.

/* 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 */
原文链接:https://www.f2er.com/css/217769.html

猜你在找的CSS相关文章