Welcome Guest, Not a member yet? Register   Sign In
Matching Dates
#3

[eluser]james182[/eluser]
i am trying to get a number count of events on a specific date.

database field name "event_date_begin" and value "2012-08-04 17:00:00" but i am only needing to match against the date part.

DB
Code:
INSERT INTO `default_eventcal` (`id_eventcal`, `user_id`, `event_date_begin`, `event_date_end`, `event_title`, `event_content`, `event_repeat`, `event_repeat_prm`, `privacy`)
VALUES
(2, 1, '2012-08-04 10:00:00', '2012-08-04 17:00:00', 'Picnic', 'This will be a great day.', 0, '{\"type\":\"0\",\"time\":\"0\",\"day\":\"0\",\"date\":\"1\"}', 'public'),
(3, 1, '2012-08-04 16:32:00', '2012-08-04 21:00:00', 'Another Event', 'Cool', 0, '{\"type\":\"0\",\"time\":\"0\",\"day\":\"0\",\"date\":\"1\"}', 'public'),
(4, 1, '2012-08-23 13:01:00', NULL, 'Test Event', 'This is a test event for james to play with.', 0, '{\"type\":\"0\",\"time\":\"0\",\"day\":\"0\",\"date\":\"1\"}', 'private'),
(5, 1, '2012-08-16 21:58:00', NULL, 'werwerwer', 'werwer', 0, '{\"type\":\"0\",\"time\":\"0\",\"day\":\"0\",\"date\":\"1\"}', 'private'),
(6, 1, '2012-08-16 22:03:00', NULL, 'test priv', 'asd', 0, '{\"type\":\"0\",\"time\":\"0\",\"day\":\"0\",\"date\":\"1\"}', 'private');

index.php
Code:
echo '<span class="count_events">'. event_counter($current_year, $current_month, $day) .'</span>';

helper.php
Code:
if (!function_exists('event_counter'))
{
function event_counter($year, $month, $day)
{
  $dated = $year .'-'. $month .'-'. $day;
  $date_is = date('Y-m-d', strtotime($dated));

  $counted_events = ci()->calendar_m->count_date_events($date_is);

  return print_r($counted_events);
}

}

calendar_m->count_date_events()
Code:
function count_date_events($date_is)
    {
  
  return  $this->db
      ->select("DATE_FORMAT(`event_date_begin`,'%Y-%m-%d') AS event_date_begin", FALSE)
            ->where('event_date_begin', $date_is)
      ->from('eventcal')
                  ->count_all_results();
    }

I get 1 but thats wrong.


Messages In This Thread
Matching Dates - by El Forum - 08-16-2012, 04:50 AM
Matching Dates - by El Forum - 08-16-2012, 05:37 AM
Matching Dates - by El Forum - 08-16-2012, 09:11 PM
Matching Dates - by El Forum - 08-16-2012, 10:22 PM
Matching Dates - by El Forum - 08-16-2012, 10:50 PM
Matching Dates - by El Forum - 08-17-2012, 12:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB