Iterating through dates in seperate mysql fields $d,$m,$y

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
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Iterating through dates in seperate mysql fields $d,$m,$y

Post by deejay »

What I have is a two table in a mysql database. 'listings' with property details

in and 'weeks' which stores the dates in the format dayID, weekID, YearID.
This gives me the start day for when a place will be available.

Upto now I have only needed to do a search on the months before and after the month

being searched but now I need to find out whether the property is actually available

on the date being searched.

I can search on the date values no problem

Code: Select all

$query1 = "SELECT * FROM listings LEFT JOIN weeks ON weeks.rid = listings.rid WHERE listings.rid = '$rid' AND weeks.dayID = '$day' AND weeks.monthID = '$month' AND weeks.yearID = '$year'";
 

what I can't get my head around is the best way to iterate through the last 7 days & next 7 days. Should I try to use foreach and store results in a array and then check the array. Has anyone here had to do anything similar?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Iterating through dates in seperate mysql fields $d,$m,$y

Post by aceconcepts »

If I understand you correctly you could take a look at strtotime http://uk2.php.net/strtotime
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: Iterating through dates in seperate mysql fields $d,$m,$y

Post by deejay »

Thanks,

I read through the strtotime page and gave it some thought, what I came up with was to get a start_date and end_date through my form and then make an array of all the days I needed to search and then to use foreach to each one through my mysql.


Cheers
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Iterating through dates in seperate mysql fields $d,$m,$y

Post by aceconcepts »

Cool, glad it works :D
Post Reply