Is it possible to detect the cell type in your database?
I thought it would be smart if you could output form elements based on the cell type. So if the cell type is text then you would get <textarea></textarea> and if it was varchar then it would be <input type="text" />.
Is this possible?
Detect db cell type - WORKS
Moderator: General Moderators
Detect db cell type - WORKS
Last edited by psurrena on Fri Dec 12, 2008 9:16 am, edited 1 time in total.
Re: Detect db cell type -WORKS!
It works! Thank you.
A bit of this is from php.net
A bit of this is from php.net
Code: Select all
$sql="select * from people";
$result = mysql_query($sql) or die (mysql_error());
while($meta = mysql_fetch_field($result)){
echo $meta->name.": ";
if($meta->type=="string"){
echo '<input type="text" name="'.$meta->name.'"';
if($meta->max_length <= '5'){
echo ' size="'.$meta->max_length.'"';
}
echo " />\n";
}
if($meta->type=="blob"){
echo '<br /><textarea name="'.$meta->name."\" /></textarea>\n";
}
echo "<br />";
}