Login   Register  
PHP Classes
elePHPant
Icontem

File: class.pop.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of sujith nair  >  populate_sel  >  class.pop.php  >  Download  
File: class.pop.php
Role: ???
Content type: text/plain
Description: Class to populate the <select> form field from mysql table
Class: populate_sel
Author: By
Last change:
Date: 2001-09-14 01:56
Size: 1,187 bytes
 

Contents

Class file image Download
<?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
}



?>