How to add an addtional count per 4 items

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

How to add an addtional count per 4 items

Post by danjapro »

I would like to add another count that after every 4 items, it loops and create a added piece of script, by adding <ul><li> tags after every 4 items.

I want to addthis piece of code, every fours items after it close </div>

Code: Select all

            <ul>				
               <li>
                <div class="box">
             <!--All fields and information here-->
                </div>
               <div class="h2"></div>
                <div class="box">
             <!--All fields and information here-->
                </div>
               <div class="h2"></div>
                <div class="box">
             <!--All fields and information here-->
                </div>
               <div class="h2"></div>
                <div class="box">
             <!--All fields and information here-->
                </div>
               <div class="h2"></div>
                   </li>
              </ul>

I currently have this piece of code, which builds a list per every <div class="box">, then closes the item </div> and start another one as same.
SEE current CODE.

Code: Select all


 <?php
    $dealList = $this->dealList;
    if(count($dealList)==0) echo '<h3>'.JText::_('NO_DEAL_MESSAGE').'</h3>';
	$count = 1; 
	foreach ( $dealList as $row): 
		$link = 'index.php?xxx=' . $row->id;
		if(!Helper::is_urlEncoded($row->pic_dir))
		 {
		 	$imageUrl = $row->pic_dir;
		 }
		 else
		 {
			$imageUrlArr= unserialize(urldecode($row->pic_dir));
			$imageUrl = str_replace("\\","/",$imageUrlArr[0]);
		 }
?>

<div class="box">
information fields here 
</div>


  <?php if ($count%2==1){?>
     <div class="h2"></div>
    <?php }
    else if($count%2==0){?>
    <div class="h3"></div>
   <?php  }$count++ ; endforeach;?>
How do I added the Additonal count for efter four items <div class=box"> it places and start over with

Code: Select all

<ul>
  <li>
     <div class="box">
      information fields 
     </div>
 </li>
</ul>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to add an addtional count per 4 items

Post by Celauran »

Code: Select all

if ($count % 4 == 0) { do something here }
Post Reply