<?php
// Class to populate the <select> form field from mysql table
// Made By Sujith Nair [sujith_77@hotmail.com]
// On September 14, 2001
// Please go through another class called "multi" which allows
// to populate multiple selected fields from the records.
class populate_sel {
var $hname="<hostname>";
var $uname="<username>"; // if any
var $pname="<password>"; // if any
var $dbname="<database name>";
var $tname;
var $fname;
var $sel;
// Constructor
function populate_sel($t_name,$f_name,$sel="")
{
$this->tname=$t_name;
$this->fname=$f_name;
$this->sel=$sel;
}
function display()
{
$db=mysql_connect($this->hname);
mysql_select_db($this->dbname,$db);
$sql="select $this->fname from $this->tname";
$res=mysql_query($sql);
while($myrow=mysql_fetch_array($res)) {
if($this->sel) {
if($myrow[$this->fname]==$this->sel)
{
$val.="<option selected>".$myrow[$this->fname]."</option>";
}
else
{
$val.="<option>".$myrow[$this->fname]."</option>";
}
}
else{
$val.="<option>".$myrow[$this->fname]."</option>";
}
}
echo $val;
}
// End of class
}
?> |