Here is a line of my code
while($row = mysql_fetch_array($result))
I want to get how many columns are in the row. I tried count($row) but this returned what I think is the number of cells for the whole $results.
i.e there are actually 7 columns, and 2 rows and count($row) returned 14. I want a function that will return 7.
Can you see where I’m going wrong.
Thanks in advance.
EDIT – Answer found
Passed MYSQL_NUM as a second parameter to mysql_fetch_array.
Thanks anyway to everyone’s answers.
When you use
mysql_fetch_arrayeach row has the columns indexed twice, once by column number and once by column name. Socount($row)will be twice the number of columns.Use
mysql_fetch_rowif you only want numerical indices, andmysql_fetch_associf you want name indices. These functions will both return rows with 7 entries.