Jump to content

Php-Mysql Fetch the events of this month?


jalmz

Recommended Posts

Hi guys,

 

Im having problem on how to achieved this one.. I would like to get the all event of this month (April

) Starting todays date..

 

 $now = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+8,   gmdate("Y")));

  $week = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+30,   gmdate("Y")));
  
if ($result = mysql_query("SELECT * FROM fiesta WHERE sta_date BETWEEN '$now' AND '$week' ORDER BY sta_date LIMIT 10")){ 

  if (mysql_num_rows($result)) {

  $return = ''; 
  while ($row = mysql_fetch_array( $result )) { 
        
  $date = date("D",strtotime($row["sta_date"])); 

  $return .=  "<a href='sta.php' style='font-size:11px;' title='" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "'>" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "</a> ($date), ";
   }

    echo rtrim($return, ', ');
  }
}

 

 

The result of this query will include the events on May..

 

How can i display only the event on this month(April)? starting todays date.

 

Thank you

Link to comment
Share on other sites

Forget all the php date functions. Use MYSQL functions! I hope that the sta_date field in  your database is of DATE type

 

SELECT * FROM fiesta WHERE MONTH(sta_date) = MONTH(CURDATE()) AND YEAR(sta_date) = YEAR(CURDATE()) AND DAY(sta_date) >= DAY(CURDATE()) ORDER BY sta_date

 

The above will give you all records of the current month & year that are on or in future of todays date. Test the query out before using it in your php code.

Link to comment
Share on other sites

Thanks for the reply it works perfectly.. what about today's date + 7.

 

SELECT * FROM fiesta WHERE MONTH(sta_date) = MONTH(CURDATE()) AND YEAR(sta_date) = YEAR(CURDATE()) AND DAY(sta_date) >= DAY(DATE_ADD(CURDATE(),INTERVAL 7 DAY)) ORDER BY sta_date

Link to comment
Share on other sites

wow.. Thank you neil.. just one last question.. what about this code... that uses Unix Time Stamp?

 

$time_now = time();
$week = $time_now + 86400;
$time_tom = $time_now + 518400;


if ($result = mysql_query ("SELECT dateline, dateline_from, eventid, title FROM vb_event WHERE calendarid = 1 AND dateline_from BETWEEN '$week' AND '$time_tom' ORDER BY dateline_from LIMIT 7")) {
  if (mysql_num_rows($result)) {
    $return = '';
    while ($row = mysql_fetch_array( $result )) {  
    
      $return .=  "<a href='/forum/calendar.php?do=getinfo&e=" . $row['eventid'] . "&c=1' title='". $row['title'] . "' style='font-size:11px;'>" . $row['title'] . "</a> (". date("D", $row['dateline_from']+54000)."), ";
    }
    echo rtrim($return, ', ');
  }
  else {  
    
    echo "No events currently listed";  
}  
}

 

The result of this code is todays date + 3 days.. 

 

How can I display Todays Date + 7 days For this Month of April.

 

Again, thank you

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.