sKunKbad Posted November 5, 2007 Share Posted November 5, 2007 I've got a while loop that outputs the last 3 tips in a tipsntricks table, and I'd like to do something only for the first row. You can see there is a image in this while loop called anew.gif, and I only want it to be there for the first row(first pass through the loop). I only want to have to query the database one time, so I'm not interested in a solution with multiple queries (I already have one). I'm just doing this to learn MySQL better, but I'm stuck on this. Here's the code: <?php $thisBlurb = mysql_query("SELECT tipTitle, tipCode, tipNum FROM tipsntricks ORDER BY tipNum DESC LIMIT 3"); $color1 = "#f0e8fe"; $color2 = "#E9F3FB"; while($i = mysql_fetch_row($thisBlurb)) { $row_color = ($i['2'] % 2) ? $color1 : $color2; echo "<div style='width:420px; background-color:$row_color; border-top:dotted #567ACE 4px; padding:10px;'>"; echo "<h3 class='h2like'>"; echo "<img src='/img/wnew/anew.gif' alt='NEW! NEW! NEW!'/> "; //this is the image that I only want output once. echo "<a style='text-decoration:none;' href='/tips/".$i['2'].".php5'>".$i['0']."</a></h3>"; $blurb = preg_split('/<!--blurb split here-->/',$i['1'],-1); echo " {$blurb['0']} <p><a style='text-decoration:none;' /tips/".$i['2'].".php5'><span style='font-weight:bold'>Show me more...</span></a></p></div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/76007-solved-mysql_fetch_row-while-loop-question/ Share on other sites More sharing options...
teng84 Posted November 5, 2007 Share Posted November 5, 2007 add a counter inside your loop eg.. while....{ ++$count; if ($count==1) { echo ///.. } } Quote Link to comment https://forums.phpfreaks.com/topic/76007-solved-mysql_fetch_row-while-loop-question/#findComment-384710 Share on other sites More sharing options...
sKunKbad Posted November 5, 2007 Author Share Posted November 5, 2007 Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/76007-solved-mysql_fetch_row-while-loop-question/#findComment-384720 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.