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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.