kevincro Posted November 19, 2007 Share Posted November 19, 2007 I have a select box coded that displays MySQL data as options in the pull down menu. What I need to know is if and how I can make it so that each option has given background. Can I assign a class to each option? The code for my select box looks like this: ? // Get data to populate select box $query=("SELECT name,date FROM Applicants where number='$data_key' ORDER BY points DESC"); $result = mysql_query ($query); echo '<select name=Applicants> <option value="">Applicants</option>'; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[Name]>$nt[Name]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box //end select box ?> Link to comment https://forums.phpfreaks.com/topic/77877-select-box-help/ Share on other sites More sharing options...
phpSensei Posted November 19, 2007 Share Posted November 19, 2007 i dont understand what you mean but <?php $data = mysql_query("SELECT * FROM table_name"); // the query echo '<select name="select" class='; while($row = mysql_fetch_array($data)){ if($row['value']=="a certain number or string"){ echo 'The Class with a black background'; } elseif($row['value']=="a certain number or string"){ echo 'The Class with a white background'; } echo'> <option value="'.$row['value'].'">'..$row['value']'</option> } </select>'; ?> Link to comment https://forums.phpfreaks.com/topic/77877-select-box-help/#findComment-394184 Share on other sites More sharing options...
teng84 Posted November 19, 2007 Share Posted November 19, 2007 i dont understand what you mean but <?php $data = mysql_query("SELECT * FROM table_name"); // the query while($row = mysql_fetch_array($data)){ echo '<select name="select" class='; if($row['value']=="a certain number or string"){ echo 'The Class with a black background'; } elseif($row['value']=="a certain number or string"){ echo 'The Class with a white background'; } echo'> <option value="'.$row['value'].'">'..$row['value']'</option> </select>'; } ?> running your code will give so many drop down box? Link to comment https://forums.phpfreaks.com/topic/77877-select-box-help/#findComment-394186 Share on other sites More sharing options...
phpSensei Posted November 19, 2007 Share Posted November 19, 2007 i forgot to seperate it from the while statement. Link to comment https://forums.phpfreaks.com/topic/77877-select-box-help/#findComment-394187 Share on other sites More sharing options...
phpSensei Posted November 19, 2007 Share Posted November 19, 2007 <?php $data = mysql_query("SELECT * FROM table_name"); // the query echo '<select name="select" class="'; while($row = mysql_fetch_array($data)){ if($row['value']=="a certain number or string") { echo 'The Class with a black background' . '">'; } elseif($row['value']=="a certain number or string") { echo 'The Class with a white background' .'">'; } echo'<option value="'.$row['value'].'">'.$row['value'].'</option> } </select>'; ?> Link to comment https://forums.phpfreaks.com/topic/77877-select-box-help/#findComment-394188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.