Page 1 of 1

Need to <div> for every 4 blocks, and </div>...how?

Posted: Tue Jun 24, 2014 5:28 am
by simonmlewis
I'm trying to do a gallery here, and it shows each block of four images at a time.

So it needs to be:

Code: Select all

<div>
<img><img><img><img>
</div>


<div>
<img><img><img><img>
</div>
This isn't working. It's putting </div> when I dont want them, and then missing <div>.

Code: Select all

<div style='left: -680px;' class='items'>";

			$string = "$row->photo";
      $token = strtok($string,"|");
      $c1 = 1;
      $n1 = 5; // Each Nth iteration would be a new table row
      while($token) {

      if ($c1 == "1") { echo "<div>";}
      
 if($c1 % $n1 == 0 && $c1 != 0) // If $c1 is divisible by $n1...
  {
  echo "<div>";
  }

      echo "
      <a href='/images/productphotos/$token'  rel=\"zoom-id:Zoomer;\" rev='/images/productphotos/$token' title='$row->title' /><img  src='/images/productphotos/small/$token' border='0' /></a>";

 if($c1 % $n1 == 0 && $c1 != 0) // If $c1 is divisible by $n1...
  {
  echo "</div>";
  }
      
$token = strtok("|");
$c1++;
}

echo "</div>
I'm sure it's done with a count, and then I would have thought it's every four rows.

Re: Need to <div> for every 4 blocks, and </div>...how?

Posted: Tue Jun 24, 2014 7:54 am
by Celauran
You're creating <div> and </div> on the same iteration. You'll want to close one before opening the other.

Re: Need to <div> for every 4 blocks, and </div>...how?

Posted: Tue Jun 24, 2014 8:35 am
by simonmlewis
I think I finally got there with this version:

Code: Select all

<div style='' class='items'>";

			$string = "$row->photo";
      $token = strtok($string,"|");
      $c1 = 1;
      $n1 = 3; // Each Nth iteration would be a new table row
      while($token) {

      if ($c1 == "1") { echo "<div>";}
      
      echo "<a href='/images/productphotos/$token'  rel=\"zoom-id:Zoomer;\" rev='/images/productphotos/$token' title='$row->title' /><img  src='/images/productphotos/small/$token' border='0' /></a>";

 if($c1 % $n1 == 0 && $c1 != 0) // If $c1 is divisible by $n1...
  {
  echo "</div><div>";
  }
  $c1++;    
$token = strtok("|");

}

echo "</div>

Re: Need to <div> for every 4 blocks, and </div>...how?

Posted: Mon Jul 07, 2014 4:42 am
by simonmlewis
The problem with my solution is that it then creates an open DIV when there neednt be one.
This slider tool has to have at least 6 in it to work (for some reason).
So how do I keep wtih this opening and closing divs, but without opening a DIV at the end when once is not needed.