How to get Event from mySql Table from Between Dates???

Discussion in 'PHP' started by fdoze, Jan 15, 2010.

  1. #1
    Hi,

    I'm setting an Events Calendar.

    And I setup for each event a startDate and a endDate, Beginning and End Date for each Event.

    The thing is I'm trying to display Event Title when a user clicks on a date Calendar.

    I get the clicked Date, Day, Month and Year and I can only get value for the Event if Day one, Start Day of Event is cliecked or if the Last day , EndDate of Event is clicked...


    How can i get the mysql rows results for the Days when the evvent occurs, the days between the satrt day and the end day of the event???

    My mySQL code on php is this:

    
    	$mySql = "SELECT id, titlePt, contentTitle, startDate, endDate FROM `Events` WHERE `fkStatus` = 1 AND `fgHolliday` = 0 AND `startDate` = '".$myTimeStampClicked."' OR `endDate` = '".$myTimeStampClicked."' ORDER BY startDate ASC LIMIT 0,".$myLimit;
    
    
    PHP:
    Please , any help will be great! Thanks!!
     
    fdoze, Jan 15, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi fdoze,
    please try
    
    $mySql = "SELECT id, titlePt, contentTitle, startDate, endDate FROM `Events` WHERE `fkStatus` = 1 AND `fgHolliday` = 0 AND '".$myTimeStampClicked."' BETWEEN `startDate` AND `endDate` ORDER BY startDate ASC LIMIT 0,".$myLimit;
    
    Code (markup):
    Regards,
    Nick
     
    koko5, Jan 15, 2010 IP
  3. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey! Thanks.

    But nop.. I get no rows at all when I click and Event Day. start day, Between day or end Day.


    any clue?
     
    fdoze, Jan 15, 2010 IP
  4. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry,

    I got it.

    But now I can not get Result for the Start Day of event.

    I will try some tewaking..
     
    fdoze, Jan 15, 2010 IP
  5. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi,

    I got it working this way:

    
    	$mySql = "SELECT id, titlePt, contentTitle, startDate, endDate FROM `Events` WHERE `fkStatus` = 1 AND `fgHolliday` = 0 AND `startDate` = '".$myTimeStampClicked."' OR ('".$myTimeStampClicked."' BETWEEN `startDate` AND `endDate`) ORDER BY startDate ASC ";
    
    
    Code (markup):
     
    fdoze, Jan 15, 2010 IP
  6. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #6
    Hi,

    You can use MySQL CURDATE() function instead of php variable $myTimeStampClicked inside the query, so you'll be sure that date format is once and the same.
    Example:
    If data is stored "d-m-Y" in MySQL and your date in php variable $myTimeStampClicked was formatted "Y-m-d" you'll not get the correct result.

    Regards,
    Nick
     
    koko5, Jan 15, 2010 IP
  7. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Many thanks!
     
    fdoze, Jan 15, 2010 IP