By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,745 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,745 IT Pros & Developers. It's quick & easy.

Help regarding drop down list is required

P: 1
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","Blue" 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
Jul 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: 29
check this code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $sql_sel="select * from  tbl_mst_department";
  3.     $result=mysql_query($sql_sel)or die("Could not select the table");    
  4.         ?>
  5.         <select name="I_DepartmentID" class='textbox'>
  6.         <option value="">Select any department</option>
  7.             <? while($rowdep=mysql_fetch_array($result))
  8.             {
  9.             if($rowdep['V_DepartmentName']==$depname)
  10.             {
  11.             $select = ' selected';
  12.             }
  13.             else
  14.             {
  15.             $select = '';
  16.             }
  17.             ?>
  18.         <option value="<?=$rowdep['I_DepartmentID']?>" <?=$select;?>><?=$rowdep['V_DepartmentName']?></option>
  19.             <? }?>
  20.  
  21.         </select>
  22.  
Jul 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.