npsari Posted February 20, 2008 Share Posted February 20, 2008 Hi there I have a table called name In which, i have a row called names i use this little code to show the last 3 names $con=mysql_connect("$Connect", "$Name", "$Pass"); mysql_select_db("$Database", $con); $q = "SELECT * FROM name LIMIT 3;"; $res = @mysql_query($q); while($r = @mysql_fetch_array($res)){ print"<FONT style=\"font-size:11px\" color=\"#000000\" face=\"Arial\">$r[name]</FONT><br>"; } but i dont want all names to be black color I want the first name black (000000) the second red (ff0000) the third blue (0000FF) How can i write the above code plz Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 20, 2008 Share Posted February 20, 2008 <?php $colors = array("#000000", "#cccccc", "cc0000"); $i = 0; while(FETCHLOOP){ echo "<p style=\"color: ".$colors[$i].";\">".$row['Name']."</p>"; $i++; } ?> Basic idea Quote Link to comment Share on other sites More sharing options...
npsari Posted February 20, 2008 Author Share Posted February 20, 2008 ohh, many thanks i will use the code Quote Link to comment Share on other sites More sharing options...
richardw Posted February 20, 2008 Share Posted February 20, 2008 Here is one more approach without the array: Insert this line after the "while" statement $colors= ($colors== "#F1F5F8" ? "#006600" : "#F1F5F8"); // change colors to suit your page design echo "<p style=\"color: ".$colors.";\">".$row['Name']."</p>"; Quote Link to comment 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.