Change DIV class with PHP -


i’m trying style div’s css. want change div tag class inside mysql loop using php.

<?php $result = $mysqli->query("select * posts order id desc limit 0, 20"); while($row = mysqli_fetch_array($result))     { ?> <div class=” box id1”><?php echo $row[‘post’];?></div> <?php } ?> 

so want change class box id1 in order

box id1 box id1 box id2 box id2 box id2 box id2 box id1 box id1 box id2 box id2 box id2 box id2 on.  (2 div tags class box id1 4 box id2 looping) 

i tried using rand(1, 2); making numbers comes randomly not order want. appreciated. in advance.

<?php $result = $mysqli->query("select * posts order id desc limit 0, 20");  $i=1; $class_str = ""; while($row = mysqli_fetch_array($result)) {     switch($i%6){//deciding 6 place         //first 2 id1         case 1:         case 2:             $class_str="id1";         break;         //four other id2         case 3:         case 4:         case 5:         case 0:             $class_str="id2";         break;     } $i++;  ?>     <div class="box <?php echo $class_str; ?>"><?php echo $row['post'];?></div>  <?php } ?> 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -