Joomla Logic PHP Query with 4 parameters

Logical query

Hello,

We have 2 logic

a) The customer is contacted with the maximum time: Limitation on the marking by the number of contacts with the customer. We set the maximum time with which the client can contact the seller as 2. Having this php code

$max = 2; $listing = JRequest::getInt('listing'); if($listing) { $db = JFactory::getDBO(); $db->setQuery("SELECT COUNT(`SubmissionId`) FROM #__rsform_submission_values WHERE `FormId`='".(int) $formId."' AND `FieldName`='listing' AND `FieldValue`='".$listing."' "); $nrSub = $db->loadResult(); if ($nrSub >= $max) { $formLayout = '<p><em>Sorry, This customer has already been contacted maximum number of times</em></p>'; } } 

b) The maximum number of times a seller can contact customers in the form

 $max = 10; $user = JFactory::getUser(); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('COUNT('.$db->qn('Username').')') ->from($db->qn('#__rsform_submissions')) ->where($db->qn('FormId').'='.$db->q($formId)) ->where($db->qn('Username').'='.$db->q($user->get('username'))); $db->setQuery($query); $counter = $db->loadResult(); if ($counter >= $max){ $formLayout = '<p style="color:blue;">You have already contacted 10 customers </p>'; } 

Both work well - now we must establish the condition: - in which the dealer, if he tries to contact the same client with whom he contacted earlier, should also show an error message

Suppose it will be based on 4 parameters

Confirm the score and compare it with Max Parameter as 1

Formid

Listing

Username

Trying this code - but doesn't seem to be respected in

 $max = 1; $user = JFactory::getUser(); $listing = JRequest::getInt('listing'); if($listing) { $db = JFactory::getDBO(); $db->setQuery("SELECT COUNT('.$db->qn('Username').') FROM #__rsform_submission_values WHERE `FormId`='".(int) $formId."' AND `FieldName`='listing' AND `FieldValue`='".$listing."' "); $nrSub = $db->loadResult(); if ($nrSub >= $max) { $formLayout = '<p><strong>Sorry, You have already contacted this customer</strong></p>'; } } 

so that it matches - if the username is already associated after the form listing identifier - then an error message should appear

Maybe the username parameter should be added to the code - 1

Can someone help, help and advise you to achieve what you want - how to configure a logical query

+4
source share
1 answer

If you are using COUNT, I think you should also apply GROUP BY, for example:

 SELECT COUNT('.$db->qn('Username').') FROM #__rsform_submission_values WHERE `FormId`='".(int) $formId."' AND `FieldName`='listing' AND `FieldValue`='".$listing."' GROUP BY '.$db->qn('Username').'" 
0
source

All Articles