phily245 Posted June 30, 2011 Share Posted June 30, 2011 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"/> Quote Link to comment https://forums.phpfreaks.com/topic/240804-while-loops/ Share on other sites More sharing options...
fugix Posted June 30, 2011 Share Posted June 30, 2011 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="" />'; } } } Quote Link to comment https://forums.phpfreaks.com/topic/240804-while-loops/#findComment-1236825 Share on other sites More sharing options...
phily245 Posted June 30, 2011 Author Share Posted June 30, 2011 Thank, that solved it Quote Link to comment https://forums.phpfreaks.com/topic/240804-while-loops/#findComment-1236827 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.