Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Imroved English and formatting, added tags
Source Link
mickmackusa
  • 4.8k
  • 4
  • 18
  • 48

iI want to count select myqad1 where my formid=16the number of submissions where FieldNameformid is state16, (that FieldValue= mystate1)state is and againmystate1, FieldNameqda is qdamyqad1 (that FieldValue= myqad1)and again, and FieldNamecity is city (that FieldValue= mycity1) inmycity1.

In my example my, the count is 1 becouse oneshould be SubmissionId1 because only select andSubmissionId number 2 satisfies all requirements.

$query = $db->getQuery(true);
//$query->select('COUNT(*)');
// hove to count city that is mysity1 and state is mystate1 ??!!!
$query->select($db->quoteName('FieldValue') . ' IN ("mycity1")');

$query->from($db->quoteName('#__rsform_submission_values'));
$query->where($db->quoteName('formid') .' IN ("16")');
$query->where($db->quoteName('FieldName') .' IN ("state","qda","city")');
$query->where($db->quoteName('FieldValue') . ' IN ("mystate1","myqad1","mycity1")');
$db->setQuery($query);
$results = $db->loadObjectList();

foreach($results as $value) {
    foreach($value as $key => $data) {
        echo $data."<br />";
    }
}

Here's a rawmy attempted query, but it doesn't produce the count that I think does what I'm afterwant:

SELECT COUNT(SubmissionId)  
  FROM my_submission_values 
 WHERE FormId = '16' 
   AND FieldName ='state' 
   AND FieldValue = 'mystate1' 
   AND FieldName = 'qda' 
   AND FieldValue = 'myqad1' 
   AND FieldName = 'city' 
   AND FieldValue ='mycity1' 

i want count select myqad1 where my formid=16 FieldName is state (that FieldValue= mystate1) and again FieldName is qda (that FieldValue= myqad1)and again FieldName is city (that FieldValue= mycity1) in my example my count is 1 becouse one SubmissionId only select and

$query = $db->getQuery(true);
//$query->select('COUNT(*)');
// hove to count city that is mysity1 and state is mystate1 ??!!!
$query->select($db->quoteName('FieldValue') . ' IN ("mycity1")');

$query->from($db->quoteName('#__rsform_submission_values'));
$query->where($db->quoteName('formid') .' IN ("16")');
$query->where($db->quoteName('FieldName') .' IN ("state","qda","city")');
$query->where($db->quoteName('FieldValue') . ' IN ("mystate1","myqad1","mycity1")');
$db->setQuery($query);
$results = $db->loadObjectList();

foreach($results as $value) {
foreach($value as $key => $data) {
echo $data."<br />";
}
}

Here's a raw query that I think does what I'm after:

SELECT COUNT(SubmissionId)  
  FROM my_submission_values 
 WHERE FormId = '16' 
   AND FieldName ='state' 
   AND FieldValue = 'mystate1' 
   AND FieldName = 'qda' 
   AND FieldValue = 'myqad1' 
   AND FieldName = 'city' 
   AND FieldValue ='mycity1' 

I want to count the number of submissions where formid is 16, state is mystate1, qda is myqad1 , and city is mycity1.

In my example, the count should be 1 because only SubmissionId number 2 satisfies all requirements.

$query = $db->getQuery(true);
//$query->select('COUNT(*)');
$query->select($db->quoteName('FieldValue') . ' IN ("mycity1")');

$query->from($db->quoteName('#__rsform_submission_values'));
$query->where($db->quoteName('formid') .' IN ("16")');
$query->where($db->quoteName('FieldName') .' IN ("state","qda","city")');
$query->where($db->quoteName('FieldValue') . ' IN ("mystate1","myqad1","mycity1")');
$db->setQuery($query);
$results = $db->loadObjectList();

foreach($results as $value) {
    foreach($value as $key => $data) {
        echo $data."<br />";
    }
}

Here's my attempted query, but it doesn't produce the count that I want:

SELECT COUNT(SubmissionId)  
FROM my_submission_values 
WHERE FormId = '16' 
   AND FieldName ='state' 
   AND FieldValue = 'mystate1' 
   AND FieldName = 'qda' 
   AND FieldValue = 'myqad1' 
   AND FieldName = 'city' 
   AND FieldValue ='mycity1' 
Source Link
saeed
  • 43
  • 6

How to count aggregate data from RSForm submission values with Joomla's query building methods?

user SubmissionId FormId FieldName FieldValue
bob 2 16 state mystate1
bob 2 16 qda myqad1
bob 2 16 city mycity1
rob 3 16 state mystate2
rob 3 16 qda myqad1
rob 3 16 city mycity1
jac 4 16 state mystate1
jac 4 16 qda myqad3
jac 4 16 city mycity1
sara 5 20 state mystate1
sara 5 20 qda myqad1
sara 5 20 city mycity2

i want count select myqad1 where my formid=16 FieldName is state (that FieldValue= mystate1) and again FieldName is qda (that FieldValue= myqad1)and again FieldName is city (that FieldValue= mycity1) in my example my count is 1 becouse one SubmissionId only select and

$query = $db->getQuery(true);
//$query->select('COUNT(*)');
// hove to count city that is mysity1 and state is mystate1 ??!!!
$query->select($db->quoteName('FieldValue') . ' IN ("mycity1")');

$query->from($db->quoteName('#__rsform_submission_values'));
$query->where($db->quoteName('formid') .' IN ("16")');
$query->where($db->quoteName('FieldName') .' IN ("state","qda","city")');
$query->where($db->quoteName('FieldValue') . ' IN ("mystate1","myqad1","mycity1")');
$db->setQuery($query);
$results = $db->loadObjectList();

foreach($results as $value) {
foreach($value as $key => $data) {
echo $data."<br />";
}
}

Here's a raw query that I think does what I'm after:

SELECT COUNT(SubmissionId)  
  FROM my_submission_values 
 WHERE FormId = '16' 
   AND FieldName ='state' 
   AND FieldValue = 'mystate1' 
   AND FieldName = 'qda' 
   AND FieldValue = 'myqad1' 
   AND FieldName = 'city' 
   AND FieldValue ='mycity1'