Page 1 of 1

PHP Loop

Posted: Thu Jun 22, 2006 7:24 am
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

Posted: Thu Jun 22, 2006 7:39 am
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".

Posted: Thu Jun 22, 2006 8:12 am
by b00ker_b0y
Thanks very much! That is so simple I did not even think of it like that. Cheers GM.