Page 1 of 1

retreiving data in drop down from database

Posted: Fri Aug 21, 2009 12:22 am
by yasir_memon
i want to show the department names stored in database into drop down can any one please send me the php coding for that
thanks

Re: retreiving data in drop down from database

Posted: Fri Aug 21, 2009 12:39 am
by aceconcepts
This is one approach:

Code: Select all

 
//setup your query
$query = mysql_query("SELECT dept FROM tblDepartment ORDER BY dept");
 
//open your drop down list
echo '<select name="deptList">';
 
//initialise a loop of the query results
while($row = mysql_fetch_array($query))
{
//output you drop down list content
  echo '<option value="'.$row['dept'].'">'.$row['dept'].'</option>';
}
 
//close your drop down list
echo '</select>';
 
mysql_free_result($query);
 
I haven't tested it but that's it :D

Re: retreiving data in drop down from database

Posted: Fri Aug 21, 2009 6:40 am
by yasir_memon
this code is not working properly their is no thing in drop down after using this code can any u please send me tested code for that.

Re: retreiving data in drop down from database

Posted: Fri Aug 21, 2009 6:51 am
by juma929
Hello,

Did you just run that code or did you adjust it to match your specific requirements yasir_memon?

:dubious:

Re: retreiving data in drop down from database

Posted: Fri Aug 21, 2009 6:54 am
by yasir_memon
ofcourse dear i used this code

$conn=odbc_connect('AKTMAPP','ERP_TEST','ERP_TEST');
$sql="select dept_name from departmentfile order by dept_name";
$rs=odbc_exec($conn,$sql);
echo '<select name="dddept">';
while($row = odbc_fetch_array($rs))
{
echo '<option value="'.$row['dept_name'].'">'.$row['dept_name'].'</option>';
}
echo '</select>';