SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting dates in database table into calendar

    I am working with the php calendar at http://php.about.com/od/finishedphp1...p_calendar.htm

    I have a table in my database with fields

    Code MySQL:
    periodid int auto_increment primary key
    startdate date not null
    enddate date not null

    All dates between the startdate and enddate need to be identified on calendar. Startdate and enddate can be any dates with more than one period in a month.


    From my query to database I am creating arrays

    Code PHP:
    while ($getdates = @mysql_fetch_array($datessql))	{
    			$startdate[] = $getdates['startdate'];
     
     
    			$enddate[] = $getdates['enddate'];
    $pricesperiodid[] = $getdates['pricesperiodid'];

    then combining arrays like this

    Code PHP:
    if (isset($startdate))	{	
    			$pricesperiodstart = array_combine($pricesperiodid, $startdate);
    			}
    	if (isset($enddate))	{
    			$pricesperiodend = array_combine($pricesperiodid, $enddate);
    			}
    		}

    Help! At this point I am stuck! I am wanting to generate all the dates required into another array so that I can then check against the calendar dates using
    Code PHP:

    Or is there a completely different way anybody can suggest??

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd make a function. To make a list of dates from start to end.
    And fill an array with this.

    the only thing I don't understand is how to use periodid if there are more than one for one date.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My thinking with periodid was that I could use this to avoid confusion between various periods if we had, for example during March a startdate of 2nd and enddate of 6th and another startdate of 8th and enddate of 12th, the arrays would be something like this with the index to both arrays being the periodid.

    array( [1] => 2009-03-02 [2] => 2010-03-08 ) for startdate[] and
    array( [1] => 2009-03-06 [2] => 2010-03-12 ) for enddate[]

    However if making an array as you suggest this may be irrelevant.

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lets talk about the goal. The interface.
    What's the use of matched dates? A link with periodid? What if there are 2 periods for one date?

    Or there are a link to the certain date, and there are all periods displayed?

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think my original idea with matched dates was irrelevant and confusing the issue, and an array with all dates is a much beter idea.

    I have now had time to put the array together as Shrapnel_NS suggested like this
    Code PHP:
    while ($getdates = @mysql_fetch_array($datessql))	{
    			$startdate = strtotime($getdates['startdate']);
    $enddate = strtotime($getdates['enddate']);
    while ($startdate <= $enddate )	{
     
    		$arraydates[] = date('Y-m-d',$startdate);	
    			$startdate = $startdate + 86400;
     
    		}
     
    		}
     
    		print_r($arraydates);

    This leaves me with one discrepancy which I am struggling to rectify. The very last date that should be in the array is missing. How can I correct this without loosing the first date?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •