<i id='LldkA'><tr id='LldkA'><dt id='LldkA'><q id='LldkA'><span id='LldkA'><b id='LldkA'><form id='LldkA'><ins id='LldkA'></ins><ul id='LldkA'></ul><sub id='LldkA'></sub></form><legend id='LldkA'></legend><bdo id='LldkA'><pre id='LldkA'><center id='LldkA'></center></pre></bdo></b><th id='LldkA'></th></span></q></dt></tr></i><div id='LldkA'><tfoot id='LldkA'></tfoot><dl id='LldkA'><fieldset id='LldkA'></fieldset></dl></div>
  • <small id='LldkA'></small><noframes id='LldkA'>

  • <legend id='LldkA'><style id='LldkA'><dir id='LldkA'><q id='LldkA'></q></dir></style></legend><tfoot id='LldkA'></tfoot>
    • <bdo id='LldkA'></bdo><ul id='LldkA'></ul>

        每三个 div 的 php while 循环变量

        时间:2023-09-20
        <tfoot id='25o9H'></tfoot>

          <bdo id='25o9H'></bdo><ul id='25o9H'></ul>
            <i id='25o9H'><tr id='25o9H'><dt id='25o9H'><q id='25o9H'><span id='25o9H'><b id='25o9H'><form id='25o9H'><ins id='25o9H'></ins><ul id='25o9H'></ul><sub id='25o9H'></sub></form><legend id='25o9H'></legend><bdo id='25o9H'><pre id='25o9H'><center id='25o9H'></center></pre></bdo></b><th id='25o9H'></th></span></q></dt></tr></i><div id='25o9H'><tfoot id='25o9H'></tfoot><dl id='25o9H'><fieldset id='25o9H'></fieldset></dl></div>

            <legend id='25o9H'><style id='25o9H'><dir id='25o9H'><q id='25o9H'></q></dir></style></legend>
                <tbody id='25o9H'></tbody>

              <small id='25o9H'></small><noframes id='25o9H'>

                  本文介绍了每三个 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模板网!

                  上一篇:while循环中的php sum变量 下一篇:Jquery 循环无法正常工作?

                  相关文章

                  最新文章

                  <small id='HZbYd'></small><noframes id='HZbYd'>

                  <i id='HZbYd'><tr id='HZbYd'><dt id='HZbYd'><q id='HZbYd'><span id='HZbYd'><b id='HZbYd'><form id='HZbYd'><ins id='HZbYd'></ins><ul id='HZbYd'></ul><sub id='HZbYd'></sub></form><legend id='HZbYd'></legend><bdo id='HZbYd'><pre id='HZbYd'><center id='HZbYd'></center></pre></bdo></b><th id='HZbYd'></th></span></q></dt></tr></i><div id='HZbYd'><tfoot id='HZbYd'></tfoot><dl id='HZbYd'><fieldset id='HZbYd'></fieldset></dl></div>
                    <bdo id='HZbYd'></bdo><ul id='HZbYd'></ul>

                  1. <tfoot id='HZbYd'></tfoot>

                      <legend id='HZbYd'><style id='HZbYd'><dir id='HZbYd'><q id='HZbYd'></q></dir></style></legend>