# How to write a condition to check if a number is a multiple of 30?

How to set up an array so that instead of maximum - an array on multiples of 30 is shown

i.e \$max = 30, 60, 90, 120, 150......and so on

If array \$max matches on multiple of 30, 60, 90, 120, 150, 180, 210..... then it should display message that limits are exhausted.

``````// Define the maximum Submissions
\$max = 30;

// Get the current logged in user.
\$user = JFactory::getUser();

// Get a database connection.
\$db   = JFactory::getDbo();
\$query   = \$db->getQuery(true);

// Setup the query.
->from(\$db->qn('#__rsform_submissions'))

\$db->setQuery(\$query);

if (\$counter = \$max){
\$formLayout = '<p style="color:blue;">Your Limits are Exhausted </p>';
}
``````
• In PHP, you have to write (\$counter == \$max). Otherwise, a single = is an assignation. To check if the value exceeds \$max: (\$counter >= \$max). – Anibal Jul 29 '15 at 14:17
• The if (\$counter = \$max) { //will always be true;} Other than that, what is your question? – FFrewin Aug 28 '15 at 16:53

So you are counting all submissions 1 user has and you want to display that message when the user has 30, 60, 90, ... submissions? That doesn't make much sense to me but the solution would be to change

``````if (\$counter = \$max){
``````

to

``````if (\$counter % \$max == 0) {
``````

In computing, the modulo operation finds the remainder after division of one number by another https://en.wikipedia.org/wiki/Modulo_operation

Examples for \$max = 30:

``````10 % 30 = 10 => false [because 10 != 0]
29 % 30 = 29 => false
30 % 30 = 0  => true
59 % 30 = 29 => false
60 % 30 = 0  => true
``````
• @Ruchika this answer looks excellent to me. Is there a reason that you didn't accept this answer? Your business logic seems strange to me, so maybe I don't understand the question. Could you please accept answer that resolves your question, or if it is not resolved please update your question. – mickmackusa Jun 3 '19 at 12:39

In PHP, you have to write (\$counter == \$max), a Comparison Operator.

Otherwise, a single = is an Assignment Operator.

To check if the value exceeds \$max: (\$counter >= \$max).

Your query returns a number (count(...) - loadResult). On the other hand, you can select for all matching records (Multi-Row Results) and count the number of results (PHP's count).

• Thats correct, i missed writing in same. But the query pertains to array. How to set up an array with multiples of 30 and check for same – Ruchika Jul 29 '15 at 15:05
• Your query returns a number (count(...) - loadResult). On the other hand, you can select for all matching records (Multi-Row Results) and count the number of results (PHP's count). – Anibal Jul 29 '15 at 16:00