html - PHP While loop to display information in groups of four -


i want make slider displays 4 boxes @ time information in it. connect database , information output using while loop. possible output in groups of four, seeing have 4 boxes , repeat process many times takes. far can output 4 boxes 1 person...

<?php     include '../pinflow/configuration.php';     session_start();     $sql = "select * pin pin_profession = 'engineering' order pinid desc";     $result = mysqli_query($database,$sql) or die(mysqli_error($database));     while($rws = mysqli_fetch_array($result)){  ?>       <figure>         <img src="../pinflow/userfiles/avatars/<?php echo $rws['pin_avatar'];?>" class="active" />         <figcaption><?php echo $rws['name'];?></figcaption>         <img src="../pinflow/userfiles/avatars/<?php echo $rws['pin_avatar'];?>" class="active" />         <figcaption><?php echo $rws['name'];?></figcaption>         <img src="../pinflow/userfiles/avatars/<?php echo $rws['pin_avatar'];?>" class="active" />         <figcaption><?php echo $rws['name'];?></figcaption>       </figure>       <?php } ?> 

you may fetch resulting dataset , split in groups of length 4, using array_chunk:

<?php include '../pinflow/configuration.php'; session_start(); $sql = "select * pin pin_profession = 'engineering' order pinid desc"; $result = mysqli_query($database,$sql) or die(mysqli_error($database)); $all = mysqli_fetch_all($result, mysqli_assoc); $groups = array_chunk($all, 4); foreach ($groups $group) {?>   <figure>     <?php foreach ($group $rws) { ?>     <img src="../pinflow/userfiles/avatars/<?php echo $rws['pin_avatar'];?>" class="active" />     <figcaption><?php echo $rws['name'];?></figcaption>     <?php }?>   </figure>   <?php } ?> 

read more: http://php.net/manual/en/function.array-chunk.php


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -