Here is a simple PHP function to dynamically load data on to combo box select option. The following function retrieves data and dynamically populates combo box. In this example the function ‘getSelectList’ is called to fetch data from ‘clientsMaster’ table. ‘clientID’ and ‘clientName’ fields are requested. The function assigns clientID to combo box select option value and displays clientName in the drop down list. The list will be ordered by ‘clientName’. You can also pass condition to fetch records.

    function getSelectList ($sTable='', $sFields='', $sCond='') {
        if ($sTable == '' || $sFields == '') return;
 
        $aFields = explode(',',$sFields);
        $sCond   = ($sCond != '') ? " WHERE ".mysql_escape_string($sCond) : " ";
 
        $sql   = "SELECT DISTINCT `".mysql_escape_string($aFields[0])."`,`".mysql_escape_string($aFields[1])."`
                  FROM `".DB_PFIX.mysql_escape_string($sTable)."` ".mysql_escape_string($sCond)."
                  ORDER BY ".mysql_escape_string($aFields[1]);
 
        $result = mysql_query($sql)  or die(mysql_error());
        $rList  = '';
 
        while ($c_row = mysql_fetch_array($result)) {            
            $rList .= '<option value="'.$c_row['0'].'">'.$c_row[1].'</option>'; 
        }
        echo $rList;                                
    }

Usage:

<?php
     echo '<select id="combo1" name="client_name">'.getSelectList('clientsMaster','clientID,clientName').'</select>'; 
?>