I'm basically trying to create a Joomla JFactory query to COUNT and SELECT data if a particular field's value meets my criteria.
In "myTable", I may have several records where Field4
may either be NULL
or equal to YES
or NO
.
Ideally, I'd like a single query that would return a COUNT of records where Field1
, Field2
, and Field3
equal $Field1
, $Field2
, and $Field3
... AND then where Field4
= YES
or NO
, I'd like it to echo the text YES
or NO
, depending on if one of the records meets that criteria.
This code kind of does what I want, but it only returns a value of YES
when Field4
equals YES
. And I have a previous query above it ($db4
and $query4
) that returns the COUNT that I want. Seems like there should be a more efficient and easy way to do this.
$db5 = JFactory::getDbo();
$query5 = $db5->getQuery(true);
$query5 = $db5
->getQuery(true)
->select(array('ID', 'Field4'))
->from($db->quoteName('myTable'))
->where($db->quoteName('Field1') . " = " . $db->quote($Field1))
->where($db->quoteName('Field2') . " = " . $db->quote($Field2))
->where($db->quoteName('Field3') . " = " . $db->quote($Field3))
->where($db->quoteName('Field4') . " = " . $db->quote('YES'));
$db5->setQuery($query5);
$result5 = $db5->loadResult();
$Field4 = $result5;
echo $Field4;