Joomla 3 – sample query of the database

Here is a snippet of code I often need to build a database query in Joomla.




$db = JFactory::getDbo();
$query = $db->getQuery(true);

// Individual fields 
//$query->select($db->quoteName(array('firstname', 'lastname')));
 // or all fields
$query->select('*') ;

$db->setQuery($query);   $results = $db->loadObjectList();

 echo '<ul>';

foreach ($results as $row) {

echo "<li>{$row->firstname} {$row->lastname}</li>";


echo '</ul>';

This entry was posted in Joomla, PHP. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *