Jump to content

While loops


phily245

Recommended Posts

Hi,

 

I'm writing a function that returns image locations from a database to show in a header jQuery slideshow, so that the user can edit what images are used, via his administration panel. However, for the jQuery to work, it needs to have the first image as the active class and all the others without a class. This is the function that I have so far:

function headerReturnImages() {

$query = mysql_query("SELECT image_image FROM reviews ORDER BY image_id ASC");

      while ($fetch = mysql_fetch_array($query)) {
      echo'<img src="images/';
      echo $fetch["image_image"];
      echo '" alt="" />';
      }
}

 

This outputs:

<img src="images/img1.jpg" alt="" />

 

however, I can't seem to find a way to make it output the following code on only the first image:

<img src="images/img1.jpg" alt="" class="active"/>

 

Link to comment
https://forums.phpfreaks.com/topic/240804-while-loops/
Share on other sites

function headerReturnImages() {

$query = mysql_query("SELECT image_image FROM reviews ORDER BY image_id ASC");

      while ($fetch = mysql_fetch_array($query)) {
      if($fetch[0])
      {
      echo'<img src="images/';
      echo $fetch["image_image"];
      echo '" alt="" class="active" />';
      }
      else
      {
      echo'<img src="images/';
      echo $fetch["image_image"];
      echo '" alt="" />';
      }
   }
}

Link to comment
https://forums.phpfreaks.com/topic/240804-while-loops/#findComment-1236825
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.