| Home Ask Browse Photos Groups Advisors Widgets |
Select mysql data type?
is it possible for mysql to return a cell's data type? i want the value as well as what type of data it is (like INT, TEXT, etc)
I will post the answer to my own question, since I figured it out and other may want to know:
$table = array();
$query = 'DESCRIBE tablename';
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
$table[$row['Field']] = $row['Type'];
}
The above gets the Field names and Types in an array. Next you get the actual data:
$query = 'select * from tablename where ID = ' . $_GET['id'];
$result = mysql_query($query) or die(mysql_error());
$actualdata = mysql_fetch_assoc($result);
Now you filter through both together, matching up the field name with the field type and actual data:
foreach($table as $field=>$value) {
echo $actualdata[$field] . ' is the value of the ' . $field . ' field, which is type ' . $value . '.';
}
Hope this helps others!




