(Created page with "{{smcfunc |function=db_num_fields |usage=$smcFunc['db_num_fields'] (result) |description=Works exactly like [http://php.net/mysql_num_fields mysql_num_fields]. It gets the number...") |
No edit summary |
||
Line 22: | Line 22: | ||
<noinclude> | <noinclude> | ||
[[Category:Database Functions | [[Category:Database Functions]]</noinclude> | ||
Revision as of 21:50, 8 October 2012
Usage:
$smcFunc['db_num_fields'] (result)
Description: Works exactly like mysql_num_fields. It gets the number of fields in a result.
Parameters:
- result a query resource obtained with db_query.
Return: return exact same results as mysql_num_fields: an integer of false on failure.
Example:
// Get the fields in this row... $field_list = array(); for ($j = 0; $j < $smcFunc['db_num_fields']($result); $j++) { // Try to figure out the type of each field. (NULL, number, or 'string'.) if (!isset($row[$j])) $field_list[] = 'NULL'; elseif (is_numeric($row[$j])) $field_list[] = $row[$j]; else $field_list[] = ''' . $smcFunc['db_escape_string']($row[$j]) . '''; }