I have a solution pre-built, hooray for you.
You should be able to get the gist of what to do with this. If you don't, you can just use my database class (link in signature).
PHP Code:
function getColumns($table) {
$rr = array();
$r = $this->query("SELECT * FROM information_schema.columns".
" WHERE `TABLE_NAME`='$table'",1);
foreach($r as $key => $info) {
$len = $info["COLUMN_TYPE"]; // int(5) <-- 5 is our length
$len = explode("(",$len); // The easiest way I know to get something
$len = $len[1]; // between two strings is to explode twice and get either side.
$len = explode(")",$len);
$len = $len[0];
$rr[$info["COLUMN_NAME"]] = array(
"Column Name" => $info["COLUMN_NAME"],
"Data Type" => $info["DATA_TYPE"],
"Length" => $len,
"Null" => ($info["IS_NULLABLE"] == "YES")
);
}
return $rr;
}
Bookmarks