Home

PHP Test Page

Database Demo
Wages
Array Dump
Bogus Link
Color Table
Big Color Table <= Warning! This page is over 3 megs and will take a long time to load. It is the same as the color table except it uses all the web safe colors. Therefore it is generating a table that is 216 by 216. Load it at your own risk.

"; print_r($myfields); print_r("well, here I am"); print ""; */ /* The field objects now have 'len', 'values' and 'flags' parameters. NOTE: 'values' only has data for set and enum fields. */ //This assumes an open database connection //I also use a constant DB_DB for current database. function GetFieldInfo($table,$link) { if($table == '') return false; $fields = mysql_list_fields('test', $table, $link); if($fields){ $columns = mysql_query('show columns from ' . $table,$link); if($columns){ $num = mysql_num_fields($fields); for($i=0; $i < $num; ++$i){ $column = mysql_fetch_array($columns); $field = mysql_fetch_field($fields, $i); $flags = mysql_field_flags($fields, $i); if($flags == '') $flags=array(); else $flags = explode(' ',$flags); if (ereg('enum.(.*).',$column['Type'],$match)) $field->values = explode(',',$match[1]); if (ereg('set.(.*).',$column['Type'],$match)) $field->values = explode(',',$match[1]); if(!$field->values) $field->values = array(); $field->flags = $flags; $field->len = mysql_field_len($fields, $i); $result_fields[$field->name] = $field; $result_fields[$i] = $field; } mysql_free_result($columns); } mysql_free_result($fields); return $result_fields; } return false; } /* function mysql_enum_values($tableName,$fieldName) { $result = mysql_query("DESCRIBE $tableName"); //then loop: while($row = mysql_fetch_array($result)) { //# row is mysql type, in format "int(11) unsigned zerofill" //# or "enum('cheese','salmon')" etc. ereg('^([^ (]+)(\((.+)\))?([ ](.+))?$',$row['Type'],$fieldTypeSplit); //# split type up into array $ret_fieldName = $row['Field']; $fieldType = $fieldTypeSplit[1];// eg 'int' for integer. $fieldFlags = $fieldTypeSplit[5]; // eg 'binary' or 'unsigned zerofill'. $fieldLen = $fieldTypeSplit[3]; // eg 11, or 'cheese','salmon' for enum. if (($fieldType=='enum' || $fieldType=='set') && ($ret_fieldName==$fieldName) ) { $fieldOptions = split("','",substr($fieldLen,1,-1)); return $fieldOptions; } } //if the funciton makes it this far, then it either //did not find an enum/set field type, or it //failed to find the the fieldname, so exit FALSE! return FALSE; } The most useful thing that I can think to do with this is to populate a HTML Dropdown box with it: echo "