Help regarding drop down list is required

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • king fahid
    New Member
    • Jul 2007
    • 1

    Help regarding drop down list is required

    Hello:
    Dear i am Fahid. I need help about Drop down list.
    The problem is that i want to select by default value from dropdown list that matches with the value in the php variable.
    e.g.
    if variable value is "Red" and drop down list contains options like "Red","Yellow", "Green","Bl ue" then by default selected value should be "Red" and if variable contains "yellow" then by default selected value should be "Yellow".
    If any body knows about this problem, help me please.
    Thanks
  • sumaabey
    New Member
    • Jun 2007
    • 29

    #2
    check this code

    Code:
    <?php
    	$sql_sel="select * from  tbl_mst_department";
    	$result=mysql_query($sql_sel)or die("Could not select the table");	
    		?>
    		<select name="I_DepartmentID" class='textbox'>
    		<option value="">Select any department</option>
    			<? while($rowdep=mysql_fetch_array($result))
    			{
    			if($rowdep['V_DepartmentName']==$depname)
    			{
    			$select = ' selected';
    			}
    			else
    			{
    			$select = '';
    			}
    			?>
    		<option value="<?=$rowdep['I_DepartmentID']?>" <?=$select;?>><?=$rowdep['V_DepartmentName']?></option>
    			<? }?>
    
    		</select>

    Comment

    Working...