Joomla Module Database Query

Joomla Database Query in Module or Extension

The code belows how arrays can be fetched from a database with Joomla and pure php / mysql. The main differences in syntax are the databse connection variable and the naming of the database table. The two examples below clearly show the differences.


$db =& JFactory::getDBO();
$query = "SELECT name from #__mytable WHERE enabled=1 ";

$rows = $db->loadAssocList();
foreach ($rows as $row) {
echo "<br/><br/>My loadAssocList() method for the associative array loop count is <b>" .$row['name']."</b> records which are enabled.<br/>";

$query = "SELECT name from mytable WHERE enabled=1 ";
$result = mysqli_query($db, $query);
while ($row=mysqli_fetch_assoc($result)) {
echo $myname;