Reservation add limit

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ZeR0C00L
User
Posts: 6

Reservation add limit

Post by ZeR0C00L »

i use phpmaker simple reservation form but i need help because i known I know the initial level of php.

I get a reservation for a variety of occasions but i need to limit. would like to bring a certain limit for the same day.

I want to make a reservation to be entered to allow 40 per day

ut I do not have any idea of how to do

i use this database sample

CREATE TABLE IF NOT EXISTS reservations (
ID int(11) NOT NULL AUTO_INCREMENT,
Arrival Date date DEFAULT NULL,
Arrival Time tinytext,
Name Surname tinytext,
Room Number tinytext,
Adult Guest int(11) DEFAULT NULL,
Children Guest int(11) DEFAULT NULL,
VIP Guest tinytext,
Reservation Officer tinytext,
Chicken int(11) DEFAULT NULL,
Fish int(11) DEFAULT NULL,
Antrikot int(11) DEFAULT NULL,
Additional Requests & Notes text,
ResponseDateTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (ID)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1009 ;

Additional Requests & Notes text CHARACTER SET utf8 COLLATE utf8_bin,
ResponseDateTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (ID)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1009 ;


danielc
User
Posts: 1601

Post by danielc »

You can add a check in your reservation table Page_Load server event.
$count = ew_ExecuteScalar("SELECT COUNT(*) FROM yourtable WHERE ... "); // to count the record inserted for today.

If count is exceed your limit, perform your action.


ZeR0C00L
User
Posts: 6

Post by ZeR0C00L »

danielc wrote:
You can add a check in your reservation table Page_Load server event.
ew_ExecuteScalar("SELECT COUNT(*) FROM yourtable WHERE ... "); //
to count the record inserted for today.

If count is exceed your limit, perform your action.

ew_ExecuteScalar("SELECT COUNT(*) FROM Arrival Date ");

not working :(


danielc
User
Posts: 1601

Post by danielc »

ZeR0C00L wrote:
ew_ExecuteScalar("SELECT COUNT(*) FROM Arrival Date ");

Your syntax is not correct.
ew_ExecuteScalar("SELECT COUNT(*) FROM reservations WHERE ... "); // assume your table is reservations and put your condition if it is Arrival Date after WHERE,
// to get current date use date('Y/m/d') if your date format is YYYY/mm/dd


mobhar
User
Posts: 11747

Post by mobhar »

Put the following complete code in your Page_Load:

$val = ew_ExecuteScalar("SELECT COUNT(*) FROM reservations WHERE Arrival Date = '".date("Y-m-d")."'");
if ($val > 4) {
$this->setFailureMessage("Sorry, the reservation has been closed for today!");
$this->Page_Terminate("reservationslist.php");
}

Just tried it here, and it works properly.


ZeR0C00L
User
Posts: 6

Post by ZeR0C00L »

yes mate it is works :) but this is not control arrival date when is count 40 i cant make new reservation any other date because not opening reservationsadd.php "Sorry, the reservation has been closed for today!" but not today :)


mobhar
User
Posts: 11747

Post by mobhar »

Change this:
if ($val > 4) {

become this:
if ($val > 40) {


ZeR0C00L
User
Posts: 6

Post by ZeR0C00L »

mate 4 or 40 it does not matter when this count 4 or 40 can not make new reservation any other date. i need control day by day. but this script make limit 40 reservation limit restrict all days

i need to do this
Sunday - 40 Reservation limit
Monday - 40 Reservation limit
Tuesday - 40 Reservation limit
Wednesday - 40 Reservation limit
Thursday - 40 Reservation limit
Friday - 40 Reservation limit
Saturday - 40 Reservation limit


mobhar
User
Posts: 11747

Post by mobhar »

The SQL I gave you before has the functionality for calculating the count of reservation day to day.

"SELECT COUNT(*) FROM reservations WHERE Arrival Date = '".date("Y-m-d")."'"

See date("Y-m-d") inside the SQL. The date() function will be converted based on the day you accessed your web app. So, if for example, today is August 11, 2013, then the SQL above will be executed become:
"SELECT COUNT(*) FROM reservations WHERE Arrival Date = '2013-08-11'"

The same way also for the other date, such as August 12, 2013 (if you are accessing your web app on that day), then the SQL will be executed as:
"SELECT COUNT(*) FROM reservations WHERE Arrival Date = '2013-08-12'"

and so on.

Hopefully, the explanation above is clear enough now.


Post Reply