faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

29 of 40 people (73%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How do get the number of columns in a MySQL query?

May 14th, 2000 03:16
Richard Heyes, Zlatko Knezevic,


Like so:
$data = mysql_fetch_row($result);
$num_columns = count($data);
You could also use mysq_fetch_array() but since that brings back an 
enumerated array as well as an associative, you will need to divide the 
total by two. Like so:
$data = mysql_fetch_array($result);
$num_columns = count($data) / 2;