SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

PHP MySQL Functions to get the Field type from a result set

mysql_field_type function will return the type of field associated with the field. Different field types are varchar, char, int, blob, text, datetime etc… This command takes one result set as input along with a filed identifier or an offset. It returns a string holding filed type details. Here is the command.

string mysql_field_type(int result, int field_offset)

We will try to develop one script using our student table to display the field types of all the fields.






Related Tutorial
Printing Error message
Posting error message to an email address
PHP MySQL data display
<?
$result = mysql_query ("SELECT * FROM student");
$no_of_fields = mysql_num_fields ($result);
$no_of_records = mysql_num_rows ($result);
$i = 0;
$table_name = mysql_field_table ($result, $i);
echo "Your '".$table_name."' table has ".$no_of_fields";
echo " fields and ".$no_of_records." records <BR>";
echo "The table has the following fields <BR>";
while ($i < $no_of_fields) {
// name of the field mysql_field_name
$name = mysql_field_name ($result, $i);
echo "Field name:<b>$name</b><br>";

// Field type field mysql_field_type
$type = mysql_field_type ($result, $i);
echo "Field type:$type<br>";

$i++;
}

?>


The above code will display the field type with the fields of the student table.

The result of the above script is here

Your ’student’ table has 4 fields and 52 records
The table has the following fields
Field name:id
Field type:int


Field name:name
Field type:string


Field name:class
Field type:string


Field name:mark
Field type:int


Discuss this tutorial at forum

List of SQL Tutorials


Scripts
PHP
JavaScript
SQL Tutorial List
SQL (Home)
mysql_affected_rows mysql_change_user mysql_close mysql_connect mysql_create_db mysql_data_seek mysql_db_name mysql_db_query mysql_drop_db mysql_errno mysql_error mysql_fetch_array mysql_fetch_assoc mysql_fetch_field mysql_fetch_lengths mysql_fetch_row mysql_field_flags mysql_field_len mysql_field_name mysql_field_seek mysql_field_table mysql_field_type mysql_free_result mysql_insert_id mysql_list_dbs mysql_list_fields mysql_list_tables mysql_num_fields mysql_num_rows mysql_pconnect mysql_query mysql_result mysql_select_db mysql_tablename
SQL site Map
Knowledge Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.