Jump to content

Changing colour of text or row in a list form


madspof

Recommended Posts

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 :-)

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>"; }
			?>

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"; }
?>

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"; }

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 :-)

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 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.