rodin Posted September 11, 2007 Share Posted September 11, 2007 Hi Everyone, I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for. Can anyone help me get the Agreed? table's background color to the colors above? Any help is GREATLY appreciated! <?php error_reporting(7); $db = mysql_connect("localhost","......",".....") or die("Problem connecting"); mysql_select_db(".....") or die("Problem selecting database"); $query = "SELECT * FROM rules ORDER BY username"; $result = mysql_query($query) or die ("Query failed"); //let's get the number of rows in our result so we can use it in a for loop $numofrows = mysql_num_rows($result); echo "<TABLE BORDER=\"1\">\n"; echo "<TR bgcolor=\"lightblue\"><TD>UserID</TD><TD>UserName</TD><TD>Agreed?</TD><TD>Date Agreed</TD></TR>\n"; for($i = 0; $i < $numofrows; $i++) { $row = mysql_fetch_array($result); //get a row from our result set if($i % 2) { //this means if there is a remainder echo "<TR bgcolor=\"yellow\">\n"; } else { //if there isn't a remainder we will do the else echo "<TR bgcolor=\"white\">\n"; } echo "<TD>".$row['userid']."</TD><TD>".$row['username']."</TD><TD>".$row['diduseragree']."</TD><TD>".$row['dateagreed']."</TD>\n"; echo "</TR>\n"; } //now let's close the table and be done with it echo "</TABLE>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/68771-table-background-color-based-on-results-from-mysql-table/ Share on other sites More sharing options...
cooldude832 Posted September 11, 2007 Share Posted September 11, 2007 the easier solution to a for loop is while($row = mysql_fetch_array($result)){ That will go through any way i'm assumign your accpet terms filed is bool in type so where it outputs say something like if($row['Agreed'] >0){echo "bgcolor = \"green\"";} else{echo "bgcolor =\"red\"";} with the tags around it and it will work Link to comment https://forums.phpfreaks.com/topic/68771-table-background-color-based-on-results-from-mysql-table/#findComment-345706 Share on other sites More sharing options...
rodin Posted September 11, 2007 Author Share Posted September 11, 2007 Thanks for the reply! I am using 1 = Agreed, 2 = Disagreed 3 = Agreed 2nd Time as my query. I don't think I understand where to go w/ the code given though? Link to comment https://forums.phpfreaks.com/topic/68771-table-background-color-based-on-results-from-mysql-table/#findComment-345709 Share on other sites More sharing options...
rodin Posted September 11, 2007 Author Share Posted September 11, 2007 Nevermind, got it working w/ a variation of your code! Thanks very much! Link to comment https://forums.phpfreaks.com/topic/68771-table-background-color-based-on-results-from-mysql-table/#findComment-345784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.