Current row?

I have a full screen slideshow. The photos are located in divs with a class called slide. The first image needs to have an extra class. How should I accomplish that. I am used to use Coldfusion. There the declaration would look like this:

<div class="slide <cfif grySlideshow.currentrow eq 1>active</cfif>">

How should I do that in PHP?

Thank you in advance!

How are you getting the row info?

Hi siteguru, thank you for the reply.

This is the query:


  $grySlideshow = $pdo->query("
                       SELECT
					            photo_id,
	                            photo							
					   FROM
				                slideshow_photos			

					   ORDER BY RAND() LIMIT 9		
                   ");

So I need to address the first image. The query is returning 9 images! So the first image returned from that query needs to have that extra class!

Presumably you’ll have some kind of while() loop to retrieve each image?


$first = true;
while ($grySlideshow->fetch()) {
   if ($first) {
    // do something on the first one
    $first = false;
    }
  else {
    // do something on the others
  }
}

Hi droopsnoot. Thanks for the reply. So it should be something like this:


  $first = true;
  while($row = $grySlideshow->fetch()) {
	  if ($first) {
		  echo "<div class='slide active'>{$row['photo']}</div>";
	  }
	  else {
		  echo "<div class='slide'>{$row['photo']}</div>";
		
	  }
  }

Yes, but don’t forget to reset the ‘first’ flag:


$first = true;
  while($row = $grySlideshow->fetch()) {
      if ($first) {
          $class = "slide active";
          $first = false;
      }
      else {
          $class = "slide";
      }
     echo "<div class='$class'>{$row['photo']}</div>";
  }