Hello friends,

I have a php page that displays data from a mysql DB. Fields are

1. Username
2. Designation
etc...

I want to list usernames in a listbox. I know thats not a tough job but I want to give different colors (or background color) to usernames with different designation.

ie. All usernames with designation "Teamleader" should have same color and "Manager" should have different color.

Can someone help me?...

Recommended Answers

Try this code.

<?php
while($rows=mysql_fetch_array($result))
{
	$style = '';
	if($rows['designation']=="Teamleader")
		$style = 'style="color:#0000FF;"';
	if($rows['designation']=="Manager")
		$style = 'style="color:#cc0000;"';
	
echo "<option value=".$rows['username']." ".$style.">".$rows['username']."</option>";
}
?>
Jump to Post

All 4 Replies

post your code

<?php
while($rows=mysql_fetch_array($result)){
echo "<option value=".$rows['username'].">".$rows['username']."</option>";
}?>

If $rows is "Teamleader" then the font color of $rows should set to blue color.

If $rows is "Manager" then the font color of $rows should set to red color.

I just want to highlight username in listbox according to respective designation.

Try this code.

<?php
while($rows=mysql_fetch_array($result))
{
	$style = '';
	if($rows['designation']=="Teamleader")
		$style = 'style="color:#0000FF;"';
	if($rows['designation']=="Manager")
		$style = 'style="color:#cc0000;"';
	
echo "<option value=".$rows['username']." ".$style.">".$rows['username']."</option>";
}
?>

Thanks "vibhadevit". It works perfect!..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.