reducing number...
am 21.10.2006 10:54:01 von plato
Not a php or sql wiz but working on a form that is linked to a sql database.
I want to put a statement at the top of the form that says
" there are currently '20' places remaining in this workshop".
Each time a person submits a form I want the page to reduce the number by 1
until when n=0 it displays in red 'there are no places available in this
workshop'
thanks
plato
I'm thinking it could work off the ID on the database.
Re: reducing number...
am 21.10.2006 11:38:10 von Peter
> Not a php or sql wiz but working on a form that is linked to a sql
> database.
> I want to put a statement at the top of the form that says
> " there are currently '20' places remaining in this workshop".
> Each time a person submits a form I want the page to reduce the number by
> 1
> until when n=0 it displays in red 'there are no places available in this
> workshop'
>
> thanks
>
> plato
>
> I'm thinking it could work off the ID on the database.
>
You should not really use the ID for this type of thing. What you would be
best doing is is
$query = 'SELECT '.$places_available.'-COUNT(\'field_name\') FROM
table_name;';
if of course there are some places that should not be counted then use a
where clause on it. $places_available would be set in your php script to the
maximum amount of people that can be on the workshop. After the query before
displaying the form you should do a check to ensure the result is greater
than 0. You should also check if it is greater than 0 before submitting
their data to the database (in the event that someone has submitted at the
same time as someone else or has left the page open for some time before
submitting), this would of course stop over booking.
Re: reducing number...
am 23.10.2006 10:32:11 von Captain Paralytic
plato wrote:
> Not a php or sql wiz but working on a form that is linked to a sql database.
> I want to put a statement at the top of the form that says
> " there are currently '20' places remaining in this workshop".
> Each time a person submits a form I want the page to reduce the number by 1
> until when n=0 it displays in red 'there are no places available in this
> workshop'
>
> thanks
>
> plato
>
> I'm thinking it could work off the ID on the database.
Just did this sort of thing recently with an application to allow
booking of courses.
One table holds details of the course (workshop) including the total
number of places available (in a single row).
A second table has one row per booking with all the details of who has
booked.
Then you join the 2 tables and take the number of bookings away from
the total number available.