Bricktop Posted April 8, 2008 Share Posted April 8, 2008 Hi guys and gals, Bit of a question for you. I have built a gallery script and everything works just great. However, I am using a third-party Javascript tool to display the images. It takes images in an unordered list and outputs them. But, the first image it displays needs <li class="active"> to highlight that image when the page loads. All other images just have <li> preceeding them. So, my code goes: $sql = mysql_query("SELECT * FROM gallery ORDER BY id"); $cntavs=0; while ($a = mysql_fetch_array($sql)) { $content .= '<li><img src="'.$a['path'].''.$a['filename'].'" alt="'.str_replace('"','"',$a[description]).'" title="'.str_replace('"','"',$a[description]).'" /></a></li>'; } The above code works fine, but obviously the first image in the database does not have the <li class="active"> applied to it. I hope I have made myself clear, any idea on how I can make the first output have the active class applied? Thanks in advance! This Link to comment https://forums.phpfreaks.com/topic/100100-how-to-grab-first-mysql-row/ Share on other sites More sharing options...
luca200 Posted April 8, 2008 Share Posted April 8, 2008 $sql = mysql_query("SELECT * FROM gallery ORDER BY id"); $cntavs=0; $firstRow = true; while ($a = mysql_fetch_array($sql)) { $class = $firstRow ? ' class="active"' : ''; $content .= '<li' . $class . '><img src="'.$a['path'].''.$a['filename'].'" alt="'.str_replace('"','"',$a[description]).'" title="'.str_replace('"','"',$a[description]).'" /></a></li>'; $firstRow = false; } Link to comment https://forums.phpfreaks.com/topic/100100-how-to-grab-first-mysql-row/#findComment-511828 Share on other sites More sharing options...
Bricktop Posted April 8, 2008 Author Share Posted April 8, 2008 You sir, are a scholar and a gent. Thank you very much - it worked a treat Link to comment https://forums.phpfreaks.com/topic/100100-how-to-grab-first-mysql-row/#findComment-511830 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.