This topic is locked

Limiting the number of 'guests' that can be on a 'tour'

7/27/2011 7:16:41 AM
PHPRunner General questions
P
pim author

Hi
I have a table called Tours and a table called Guests. In the Guest table is a (lookup) dropdown where the form-user can select a tour (from the Tours Table) for the specific guest.
For each tour in the Tours table should be a maximum of guests allowed, lets say 20 Guests maximum for all TourID's.

In my case the maximum of guests for all tours stays always the same, regardless of which TourID.
How could achieve I this?
Thanks in advance for answering,
Pim:blink:

Sergey Kornilov admin 7/27/2011

You will need to implement BeforeAdd event of Guests table to check the current number of guests and reject adding the record of number of guests is 20 already.
Here is the sample code:

global $conn;

$str = "select count(*) as c from Guests where TourID = ".$values["TourID"];

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

if ($data["c"]<20)

return true;

else

{

$message = "There are already 20 guests on this tour. Choose another tour";

return false;

}