Actions

JDatabase/loadResult

From Joomla! Documentation

Revision as of 16:02, 4 March 2011 by Strixy (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

$result=$db->loadResult();

returns the first column from a row or a single specified column similar to the MySQL function "mysql_fetch_row()" if you specify a single column.

returns null if the query fails.

Example 1:

$query = "SELECT username FROM jos_users WHERE id = 62"; $db = & JFactory::getDBO(); $db->setQuery( $query ); $username = $db->loadResult();

Returns 'admin' (the username for userid 62).

Example 2:

$query = "SELECT * FROM jos_users WHERE id = 62";

Would only return '62', the value of the first column in the table. In this case, that's the id of the user.

You can use either loadRow or loadAssoc to fetch a full row depending on how you want your results formatted.