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
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Tue Jun 24, 2014 5:28 am
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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Tue Jun 24, 2014 7:54 am
You're creating <div> and </div> on the same iteration. You'll want to close one before opening the other.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Tue Jun 24, 2014 8:35 am
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>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Mon Jul 07, 2014 4:42 am
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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.