madspof Posted February 25, 2009 Share Posted February 25, 2009 Hi guys i need to change the colour of a row in a list form depending on a value from a mysql database, I know how to get the data from the mysql database and put it into the list form but i am not sure how i can change the colour of the text depending if a value is 0 or not :-s basicaly i want it to look like this 1.admin 2.user1 3.user2 4.user3 5.naughty user this would all be in a list form that once the user has been selected it would be submited. So basicaly can i change the colour in the list form is there a bit of html code that will let me do this that i could incorprate into teh loop?? thanks before hand madspof :-) Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/ Share on other sites More sharing options...
phpdragon Posted February 25, 2009 Share Posted February 25, 2009 run loop if ($value=='0') { $color='red'; } if ($value=='1') { $color='blue'; } <font color='$color'><?php echo $value; ?></font> Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/#findComment-770909 Share on other sites More sharing options...
madspof Posted February 25, 2009 Author Share Posted February 25, 2009 Well i can see things wrong with that already lol but i will fix it and try it. but really i am trying to find out what html code tells the list form what colour the text should be . thanks anyway Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/#findComment-770912 Share on other sites More sharing options...
phpdragon Posted February 25, 2009 Share Posted February 25, 2009 here is a form i use to do it it works the same I reckon you will get how it works now i assumed you knew the while loop bit sorry <?php $sql="SELECT COUNT(orderID),userID,status FROM orders GROUP BY status ORDER BY FIELD(status, 'Pending', 'Allocated', 'Packed', 'Completed')"; $result=mysql_query($sql); while($result_row=mysql_fetch_array($result)) { $orders=$result_row['COUNT(orderID)']; $status=$result_row['status']; if ($status=='Pending') { $color='red'; $newStatus='Pending'; } if ($status=='Allocated') { $color='blue'; $newStatus='Allocated'; } if ($status=='Packed') { $color='green'; $newStatus='Packed'; } if ($status=='Completed') { $color='purple'; $newStatus='History'; } echo "<form name='view' method='post' action='orderStatus.php' target='_self'><tr bgcolor='#FFFFCC'><td align='left' class='reslogin' width='170px'> <b>($orders)</b> orders <font color='$color'><b>$status</b></font>.<input name='status' type='hidden' value='$status'></td><td align='center'><input type='submit' name='submit' value='View $newStatus'></td></tr></form>"; } if ($orders<=0) { echo "<tr bgcolor='#FFFFCC'><td class='reslogin' colspan='2'> <b>(0)</b> orders.</td></tr>"; } ?> Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/#findComment-770913 Share on other sites More sharing options...
madspof Posted February 25, 2009 Author Share Posted February 25, 2009 I tried that code and it didnt change the colour of the text :-( does this work in firefox and i.e ? Still stuck anyone got any ideas ? thanks before hand :-) Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/#findComment-770997 Share on other sites More sharing options...
phpdragon Posted February 25, 2009 Share Posted February 25, 2009 post the code you used and we can see whats wrong, that code is cross browser compliant. You dont need the COUNT bit unless your wanting to count the number of entries. Here is an example similar to what you need I beleive. <?php $sql="SELECT * FROM table"; $result=mysql_query($sql); while($result_row=mysql_fetch_array($result)) { $user=$result_row['user']; $value=$result_row['value']; if ($value=='0') { $color='blue'; } if ($value=='1') { $color='red'; } echo "<font color='$color'>$user</font><br/>" } if (empty($users)) { echo "No users"; } ?> Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/#findComment-771065 Share on other sites More sharing options...
phpdragon Posted February 25, 2009 Share Posted February 25, 2009 I missed a ; on the end of the main echo statement change echo "<font color='$color'>$user</font><br/>" to echo "<font color='$color'>$user</font><br/>"; and change if (empty($users)) { echo "No users"; } to if (empty($user)) { echo "No users"; } Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/#findComment-771081 Share on other sites More sharing options...
madspof Posted February 25, 2009 Author Share Posted February 25, 2009 Thats what i already have, i just cant physicaly change the colour of the text in list form i think this is more of a html problem. I cant even get the colour of the text to change when not using php. Just to make sure this is what i mean by http://en.wikipedia.org/wiki/List_box hope this will help you understand thanks before hand :-) Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/#findComment-771155 Share on other sites More sharing options...
phpdragon Posted February 25, 2009 Share Posted February 25, 2009 Ok dont need to use font, sorry didnt realise you meant inside a form list box I just thought you meant a list of text. same code but look what i do to change the color <select size="5" multiple="multiple"> <?php $sql="SELECT * FROM table"; $result=mysql_query($sql); while($result_row=mysql_fetch_array($result)) { $user=$result_row['user']; $value=$result_row['value']; if ($value=='0') { $color='blue'; } if ($value=='1') { $color='red'; } ?> <option style='color:<?php echo $color; ?>;'>$user</option> <?php } if (empty($users)) { echo "<option>No Users</option>"; } ?> </select> that should fix the problem Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/#findComment-771463 Share on other sites More sharing options...
phpdragon Posted February 26, 2009 Share Posted February 26, 2009 and if your want to change the background color, ad a variable for it eg($bg='yellow'), then modify your style tag like such <option style="color:$color;background-color:$bg;"> Link to comment https://forums.phpfreaks.com/topic/146839-changing-colour-of-text-or-row-in-a-list-form/#findComment-771475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.