Quick if/else question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Quick if/else question

Post by MiniMonty »

Hi all,

I'm building a booking system (LAMP).
I have a row "places" (an INT) which has the number of available places on any given course.
The starting value is 10.

I can subtract from the available places each time a booking is made like this:
$result = mysql_query ("UPDATE live_1 SET places = places -1");
But if I run the script again and again it goes into minus figuers -1, -2, -3 etc.

As a Flasher I know how to limit this to zero in Actionscript with an if statement like this:
if (places == -1) {
places = 0
}

but I'm struggling to get the syntax right in php.
Any ideas ?

Best wishes
Monty
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Quick if/else question

Post by MiniMonty »

Solved it....

$result = mysql_query ("UPDATE live_1 SET places = places -1 WHERE places > 0");
Post Reply