Wednesday, December 12, 2018

Joomla 3 – sample query of the database

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

 


<?php

<?php

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

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

$query->from($db->quoteName('#__free_month')); 
$db->setQuery($query);   $results = $db->loadObjectList();

 echo '<ul>';

foreach ($results as $row) {

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

}

echo '</ul>';


?>

0 Comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>