Taki kod znalazłem na Zendzie:
<?php
class DBtable2form {
//these vars determine whether to use default form input type
//or alternate based on field size
//enum field default is select, alternate is radio
//set field default is multiselect, alternate is checkbox
//blob or text field default is textarea, alternate is text
var $enumField_toggle = 3;
var $setField_toggle = 4;
var $strField_toggle = 255;
//these vars determine form input size attributes
var $textInputLength = 50;
var $textareaRows = 4;
var $textareaCols = 50;
var $multiSelectSize = 4;
//class constructor sets form name and gets table info
//args are DB link, DB name, table name
function DBtable2form(&$conn,$DB,$table){
$this->formName = $this->table = $table;
or
die(\"DB, table or connection error.\");
}
//The following function modified from php.net:
//http://www.php.net/manual/en/function.mysql-fetch-field.php
//Courtesy of: justin@quadmyre.com & chrisshaffer@bellsouth.net
function mysql_enum_values($tableName,$fieldName){
ereg('^([^ (]+)(((.+)))?([ ](.+))?$',$row['Type'],$fieldTypeSplit); //split type up into array
$fieldType = $fieldTypeSplit[1];
$fieldLen = $fieldTypeSplit[3];
if ( ($fieldType=='enum' || $fieldType=='set') && ($row['Field']==$fieldName) ){
$fieldOptions = split(\"','\",substr($fieldLen,1,-1)); return $fieldOptions;
}
}
return FALSE;
}
//this function forces a field to a specific
//form input type regardless of size
//args are field name and form input type
//form input types are as follows:
//for enum field - \"select\" or \"radio\"
//for set field- \"multiselect\" or \"checkbox\"
//for string or blob field - \"text\" or \"textarea\"
function forceType($fieldName,$inputType){
$this->forced[$fieldName] = $inputType;
}
//this function hides a field from HTML output
//arg is field name
function hideField($fieldName){
$this->hidden[$fieldName] = \"hide\";
}
//this function outputs entire form
function printForm(){
echo \"<FORM name=\"$this->formName\" action=\"\".$_SERVER['PHP_SELF'].\"\" method=POST>n\"; for ($i=0; $i<$this->columns; $i++){
$byForce = false;
if( isset($this->forced[$name]) ) $byForce = $this->forced[$name]; if( isset($this->hidden[$name]) ) $type = \"skip\";
switch($type){
case \"real\":
case \"int\":
echo \"<b>\".$name.\":</b><br>n\"; if($len<$this->textInputLength) $length = $len; else $length=$this->textInputLength;
echo \"<input type=text name=$name size=$length MAXLENGTH=$len><br><br>n\"; break;
case \"blob\":
echo \"<b>\".$name.\":</b><br>n\"; if( ($len>$strField_toggle || $byForce == \"textarea\") && $byForce != \"text\" )
echo \"<textarea name=$name rows=$this->textareaRows cols=$this->textareaCols></textarea><br><br>n\"; else echo \"<input type=text name=$name size=$this->textInputLength MAXLENGTH=$len><br><br>n\"; break;
case \"string\":
echo \"<b>\".$name.\":</b><br>n\";
if($flag == \"enum\"){
$options = $this->mysql_enum_values($this->table,$name);
if( ($len > $this->enumField_toggle || $byForce == \"select\") && $byForce != \"radio\"){
echo \"<select name=$name>n\"; foreach($options as $opt) echo \" <option value=\"$opt\">$opt</option>n\"; echo \"</select><br><br>n\"; } else {
foreach($options as $opt) echo \"<input type=radio name=\"$name\" value=\"$opt\">$opt n\"; }
}
else if($flag == \"set\"){
$options = $this->mysql_enum_values($this->table,$name);
if( ($len > $this->enumField_toggle || $byForce == \"multiselect\") && $byForce != \"checkbox\" ){
echo \"<select name=\".$name.\"[] size=$this->multiSelectSize multiple=\"multiple\">n\"; foreach($options as $opt) echo \" <option value=\"$opt\">$opt</option>n\"; echo \"</select><br><br>n\"; } else {
foreach($options as $opt) echo \"<input type=checkbox name=\"\".$name.\"[]\" value=\"$opt\">$opt n\"; }
}
else{
if($len<$textInputLength) $length = $len; else $length=$this->textInputLength;
if( ($len>$strField_toggle || $byForce == \"textarea\") && $byForce != \"text\" ) echo \"<textarea name=$name rows=$this->textareaRows cols=$this->textareaCols></textarea><br><br>n\";
else echo \"<input type=text name=$name size=$length MAXLENGTH=$len><br><br>n\"; }
break;
case \"date\":
echo \"<b>\".$name.\":</b><br>n\"; echo \"<input type=text name=$name size=10 MAXLENGTH=10 value=0000-00-00><br><br>n\"; break;
case \"datetime\":
echo \"<b>\".$name.\":</b><br>n\"; echo \"<input type=text name=$name size=19 MAXLENGTH=19 value=0000-00-00 00:00:00><br><br>n\"; break;
case \"timestamp\":
for($ts=0;$ts<$len;$ts++) $value .= \"0\";
echo \"<b>\".$name.\":</b><br>n\"; echo \"<input type=text name=$name size=$len MAXLENGTH=$len value=$value><br><br>n\"; break;
case \"time\":
echo \"<b>\".$name.\":</b><br>n\"; echo \"<input type=text name=$name size=8 MAXLENGTH=8 value=00:00:00><br><br>n\"; break;
case \"year\":
echo \"<b>\".$name.\":</b><br>n\"; echo \"<input type=text name=$name size=4 MAXLENGTH=4 value=0000><br><br>n\"; break;
case \"skip\":
break;
} //end switch
} //end for
} //end function putForm
} //end class
$objForm = new DBtable2form($resConn,'baza','tabela');
$objForm->printForm();
?>
Klasa niezła, tylko przy pracy na kilku tabelach nie zdaje egzaminu :/ ... Ale mam przynajmniej zarys