$query="select * from student";
$result=mysql_query($query);
$fields=mysql_num_fields($result);
echo $fields;
The above code will print 4 as we have 4 columns in our student table.
$query="select name,id from student";
Now the output of the print command will display 2 ( not 4 ). So the function mysql_num_fields function returns the number of columns returned by the query.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| Not known | 28-11-2009 |
| The above code duplicates the value for each cell. Any fix? | |
| smo | 15-01-2010 |
| Above code works perfectly. No problem. | |