db_num_fields

From Online Manual

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