Gallery images - can you just show first?

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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Gallery images - can you just show first?

Post by simonmlewis »

Code: Select all

echo "<div class='productgallerybox'>";
			
			$string = "$row->photo";
      $token = strtok($string,"|");
      while($token) {
      echo "
      <div>
      <a href='images/productphotos/$token' rel='lightbox[$row->id]' title='Enlarge' /><img  src='images/productphotos/small/$token' border='0' class='productsmallbox' alt='Enlarge'/></a></div>
  
";
$token = strtok("|");
}

echo "</div>
Is it possible to NOT have this loop - but stop at the first | ??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: Gallery images - can you just show first?

Post by Phoenixheart »

Your question is not clear at all I'm afraid.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Gallery images - can you just show first?

Post by simonmlewis »

Sorry.

Code: Select all

echo "<div class='productgallerybox'>";
                       
                        $string = "$row->photo";
      $token = strtok($string,"|");
      while($token) {
      echo "
      <div>
      <a href='images/productphotos/$token' rel='lightbox[$row->id]' title='Enlarge' /><img  src='images/productphotos/small/$token' border='0' class='productsmallbox' alt='Enlarge'/></a></div>
 
";
$token = strtok("|");
}

echo "</div>
This code goes through a loop to find each image file in turn, and loops around at each | sign in the field.
I want it to STOP at the first |. But have no idea how.

We have a Primary Photo field, but have been asked to use the first image in the gallery as the main photo in other areas of the site.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply