Reputation: 13
In my example I will show in other module the prices of each article. I use this code (hv try several codes) but it only shows one price on all listings. I think it's first in sql ..
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select ($db->quoteName('jr_price'));
$query->from($db->quoteName('#__jreviews_content'));
$db->setQuery($query);
$result = $db->loadResult();
print_r($result);
?>
Upvotes: 1
Views: 135
Reputation: 13
i found solution to add to code above
$result = $db->loadResult();
print_r($result);
Upvotes: 0
Reputation: 1676
You should do the following:
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select ($db->quoteName('jr_price'));
$query->from($db->quoteName('#__jreviews_content'));
$db->setQuery($query);
$prices = $db->loadColumn();
foreach ($prices as $price) {
echo $price.'<br />;
}
?>
Upvotes: 2
Reputation: 19733
loadResult()
only loads a single result. I would suggest you use loadObjectList
or loadColumn
and then use a foreach
loop to display your results.
The following documentation page will ve very helpful for you:
https://docs.joomla.org/Selecting_data_using_JDatabase
Upvotes: 1