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 Link to comment https://forums.phpfreaks.com/topic/92148-i-dont-want-the-color-to-be-repeated/ 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 Link to comment https://forums.phpfreaks.com/topic/92148-i-dont-want-the-color-to-be-repeated/#findComment-471977 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 Link to comment https://forums.phpfreaks.com/topic/92148-i-dont-want-the-color-to-be-repeated/#findComment-471984 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>"; Link to comment https://forums.phpfreaks.com/topic/92148-i-dont-want-the-color-to-be-repeated/#findComment-472058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.