I’m building a Joomla template. For this I need to test/query two fields in the DB. I’m trying to get familiar with getDBO class but stuck here.
These two queries do nearly the same. I need both variables $category and $hasField. How can merge these two queries into one? This is a bit redundant.
$db = JFactory::getDBO();
$id = JRequest::getInt('id');
$db->setQuery('
SELECT
#__categories.title
FROM
#__content,
#__categories
WHERE
#__content.catid = #__categories.id
AND
#__content.id = '.$id
);
$category = $db->loadResult();
$db->setQuery('
SELECT
#__attachments.filename,
#__attachments.parent_id
FROM
#__attachments
WHERE
#__attachments.parent_id =' . $id
);
$hasField = $db->loadResult();
You can try joining
#__attachmentsto the 1st query.