php while loop variable for every third div(每三个 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 循环变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:每三个 div 的 php while 循环变量
基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01