Db num fields: Difference between revisions From Online Manual

Jump to: navigation, search
No edit summary
m (Bot: Automated text replacement (-< +<))
 
(One intermediate revision by one other user not shown)
Line 9: Line 9:
|example=<nowiki>// Get the fields in this row...
|example=<nowiki>// Get the fields in this row...
$field_list = array();
$field_list = array();
for ($j = 0; $j &lt; $smcFunc['db_num_fields']($result); $j++)
for ($j = 0; $j < $smcFunc['db_num_fields']($result); $j++)
{
{
// Try to figure out the type of each field. (NULL, number, or 'string'.)
// Try to figure out the type of each field. (NULL, number, or 'string'.)
Line 20: Line 20:
}</nowiki>
}</nowiki>
}}
}}
<noinclude>
<noinclude>
[[Category:Database Functions]]</noinclude>
[[Category:Database Functions]]</noinclude>

Latest revision as of 11:51, 1 July 2013

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: