PHP Loop

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
b00ker_b0y
Forum Newbie
Posts: 10
Joined: Thu Jun 22, 2006 7:16 am

PHP Loop

Post by b00ker_b0y »

Hello people;

Anyone have any idea how to tackle this problem (quite new to all this):

I have a database with some dates in it, with whether they are free or not in boolean formate i.e. 1 for free and 0 for not free.

eg.

12/12/2006 1
13/12/2006 1
14/12/2006 0
15/12/2006 1

I want to be able to enter two dates, and loop from date 1 through to date 2 checking all the dates in between and see if they all = 1! and if not flag it to the user as being 0 and not free.

Any ideas would be helpful!

Thanks
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

Can't you do something like

Code: Select all

SELECT date FROM t_dates WHERE date BETWEEN '$date_from' AND '$date_to' AND free=0
?

No looping - you just pull the information directly out of the database. If no rows are returned, then the dates are all "1", if you get results, then it will return the dates with "0".
b00ker_b0y
Forum Newbie
Posts: 10
Joined: Thu Jun 22, 2006 7:16 am

Post by b00ker_b0y »

Thanks very much! That is so simple I did not even think of it like that. Cheers GM.
Post Reply