I have this problem that I can't resolve. In CMS Joomla I need to select data from table #__adsmanager_ads
column ad_healine
and from table #__modules
column title
.
Then check if ad_headline == title
load module (that equal to ad_healine)
I use this code for single table select:
<?php
Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('ad_headline')))
->from($db->quoteName('#__adsmanager_ads'));
$db->setQuery($query);
$results = $db->loadObjectList();
$objectoarr = json_decode(json_encode($results),true); // Convert stdClass object to array
print_r($objectoarr);
?>
========================================================================= Next i write code below and problem is almost solver
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select (array('a.ad_headline', 'b.title')) //Select columns from database
->from ($db->quoteName('#__adsmanager_ads','a'))
->join('LEFT', $db->quoteName('#__modules', 'b') . ' ON (' . $db->quoteName('a.ad_headline') . '=' . $db->quoteName('b.title').')');
$db->setQuery($query);
$result = $db->loadObjectList();
$objectoarr = json_decode(json_encode($result),true); // Convert stdClass object to array
foreach ($objectoarr as $adhealine){
if ($adhealine[ad_headline] === $adhealine[title])
{
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('modules');
$position = 'inside-ad';
$options = array('style' => 'raw');
echo $renderer->render($position, $options, null);
}
}
?>
But problem is that all modules set to position inside-ad
loading there. But I need load only module which's name equivalent to ads name.
How can i solve this problem? Thank in advance
loadObjectList()
you should callloadAssocList()
. this way you can avoid$objectoarr = json_decode(json_encode($result),true);
which is obviously the long way around. I would be using an INNER JOIN to eliminate the possibility of joining to NULL rows. Since the INNER JOIN will ensure that you are only getting identicalad_headline
andtitle
values in each row, you can omit the php conditional:if ($adhealine[ad_headline] === $adhealine[title])
.position = 'inside-ad'
? Is it necessary to write into the query as aWHERE
condition? Please progress all of your questions toward a system-recognized resolution. This is important to this this community for so many reasons. Please add your complete and educational answer or update your question. Thank you.