Page 1 of 1

Using style in a mysql CONCAT

Posted: Sat Nov 15, 2008 9:37 am
by Lonestarjack
Is there any way to apply a style to Category in the following so that the Category in the drop down box will show up red?

<select onchange="display_data(this.value);">
<option>Select A Company</option>
<?php
$query="select names_id as id,
CONCAT(ucase(nam_category), ', ', nam_company) AS full_name
FROM names
WHERE nam_type = 'B'
ORDER BY full_name";

$result=mysql_query($query);

while(list($id, $full_name)=mysql_fetch_row($result)) {
echo "<option value=\"".$id."\">".$full_name."</option>";
}
?>
</select>

Re: Using style in a mysql CONCAT

Posted: Sat Nov 15, 2008 9:55 am
by chopsmith
I'm not 100% certain, but I don't think you can style options in a <select>. In the past, I've bolded an option, and that only worked in IE.

Re: Using style in a mysql CONCAT

Posted: Sat Nov 15, 2008 10:00 am
by Eran

Code: Select all

 
<select onchange="display_data(this.value);" style="background-color:red;">
 
Or:

Code: Select all

 
<option style="background-color:red;"> </option>
 

Re: Using style in a mysql CONCAT

Posted: Sat Nov 15, 2008 10:24 am
by Lonestarjack
I only want the Category part on the "full name" to be red like:
Automotive, Bills Garage

Re: Using style in a mysql CONCAT

Posted: Sat Nov 15, 2008 10:30 am
by Eran
You can't style individual parts of an option element

Re: Using style in a mysql CONCAT

Posted: Sat Nov 15, 2008 10:31 am
by chopsmith
Well, I guess you can style them in the way pytrin mentions. If I were you, I'd try putting the Category portion inside of href-less anchor tags and give them a class, then style the class:

Code: Select all

 
a.categoryName {
color: red;
}
 

Code: Select all

 
<option><a class='categoryName'>Automotive</a> Bill's Garage</option>
 
Edit: tried it, doesn't work