Close subscriptions if amount is higher then...

brononius 06 Jan, 2017
Hey,

I would like to make a small registration form, that's limited in places.
For this, I want to use a small db table to keep track of it. I was able to count the open positions (see below), but I would like to lock the subscriptions once the number is reached. What the best way to this?

Custom php code to count down free places from 10 for eventA:
$sql = "SELECT * FROM DB_DATA WHERE EVENT = EVENTA";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
$free = 10 - $num_rows;
echo "For the moment, " . "$free" . "places free.";
GreyHead 06 Jan, 2017
Answer
Hi brononius,

To do this, use an Event Switcher action in the form On Load event with one event 'closed'.

Add code like this
<?php
$db = \JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__DB_DATA`
        WHERE `EVENT` = 'EVENTA' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 10 ) {
  return 'closed';
}
?>

In the closed event add a Display Message and a Show Stopper action.

Bob
brononius 07 Jan, 2017
1 Likes
NIce, is working perfectly !
(I just need to replace the 'closed' event with failed).


Thanks!!!
This topic is locked and no more replies can be posted.