db_num_fields From Online Manual

Revision as of 13:47, 16 July 2011 by Emanuele (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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]) . ''';
}



Advertisement: