1

I am trying to create a condition in which basis

Column Name Field Name Field Value

of mysql database, a conditional script should show in - Attached Table enter image description here

ColumnName - FormId Fieldname - Listing Fieldvalue - Listing Value

Below is script

$max = 1;
$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>Sorry, no more submissions are accepted for this car.</p>';
}
}

I think am messing up with Fieldvalue column - may be it might not be able to fetch in value. Can someone help and advise pls

1
  • You are quering count COUNT(SubmissionId), you have to use column names if you need values Commented Jul 12, 2015 at 7:25

1 Answer 1

1

You are Quering count, it should be column names or * for all columns, if you need values, see example below:

$db->setQuery("SELECT * FROM #__rsform_submission_values WHERE `FormId`='".(int) $formId."' AND `FieldName`='listing' AND `FieldValue`='".$listing."' ");
$nrSub = $db->loadAssocList();
print_r($nrSub);

Additionally, Please go through with for ref Joomla DB Documentation

EDIT:

$Query = "SELECT 
    COUNT(`SubmissionId`) SubmissionCount, `FormId`, `FieldName`, `FieldValue` 
    FROM #__rsform_submission_values 
    WHERE `FormId`='".(int) $formId."' AND `FieldName`='listing' AND `FieldValue`='".$listing."'
    GROUP BY `FormId`, `FieldName`, `FieldValue`";
$db->setQuery($Query);
$nrSub = $db->loadAssocList();
print_r($nrSub);
Sign up to request clarification or add additional context in comments.

7 Comments

Hello - Yes Count would be used to find total submissions based on matching parameters (Form Id, Field name, Field Value) and comparing it with maximum value of 1 as defined in query.
@Ruchika Please add, what should be desired results
Hello, Count should happen to Table basis matching - 'Form Id' & 'Listing Field' and 'Listing Field Value'. If a duplicate count is attempted to be submitted then a message should be shown - Sorry, no more submissions are accepted for this car.
@Ruchika see my updated answer, hope this is what you need! You may add more columns in SELECT / GROUP BY clause as per need.
Your code looks perfectly fine. Thanks - but i guess problem is in this line - $listing = JRequest::getInt('listing'); if($listing) { . It seems that listing value is not getting imported in it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.