Location: PHPKode > scripts > ComboBox > combobox/class.ComboBox.php
/*
** Author: Jeff Hines (hide@address.com)
** Class ComboBox
** Creates a list box using two fields.
** Assuming that the first field is the field ID and the second field is the list data.
*/

<?
require("uservariables.php3");

class ComboBox
{
     var $tableName;
     var $databaseName;
    
  
     /* Begin Edit Constructor */

     function ComboBox( $tblname, $dbname ){

        $this->tableName = $tblname;
        $this->databaseName = $dbname;
               
  
      /* Connect to database */
       if (!($link = mysql_pconnect ($hostName, $userName, $password))){
           echo("Error connecting to $hostName<BR>");
               exit();
              }

 @mysql_select_db("$this->databaseName") or die("Unable to select database");
 
 $para_query=mysql_query("select * from $this->tableName") or die(mysql_error());
      
      
 /* Begin result table */
 
 echo("<table width=100>");
 echo("<select size=\"1\" name=\"id\">");
 while ($row = mysql_fetch_array($para_query))
 {    
        
   /* Output combo box */
     
     echo("<option value=");
     echo( $row[ 0 ] );  
     echo(">"); 
     echo( $row[ 1 ] ); 
     echo("</option>");  
             
 }
 echo("</select>");
 echo("</table>");

 /* End result table */
    
  }// End Constructor
}// End Edit 
?>
Return current item: ComboBox