0

With jQuery's $.post i want to send a value to my php function , where inside it should lookup the events by it's current selected month.

Now there some programmatic problems.

First is to what value it is best to make the check against. In theory i have all available, but the ideas i have all seem to be clumsy. If it helps , i use the following script that does all the calculation with the data i provide it with. eventCalendar

For my testing purposes , just to make a check if the event is active or not i use the following code:

var Calendar = new Object();
Calendar.id = '1';//Check if active 1 or 0

var calendarJson = JSON.stringify(Calendar);                
$('#indicator').show();

$.post('Controller.php',
    {
        action: 'get_events',
        calendar: calendarJson          
    },
    function(data, textStatus) {
....more code

Were the data is retrieved and handled as:

public function getEvents($calendar){               
    $sth = $this->dbh->prepare("SELECT * FROM events WHERE current = ?");
    $sth->execute(array($calendar->id));
    return json_encode($sth->fetchAll());
}

Where in the counted result the most important data = event_sdate varchar(255)

looks like:

event_sdate = 1394220775280 (milliseconds)

However my intention is to let it send back all events by it's given month. So i have to replace current = ? with something that is inserted when create a new event. And that should, at least it is what i think, the month and year of creation.

And when make the call to the php function:

Calendar.id = '1';//Check if active 1 or 0

Should be something like:

Calendar.id = 'March 2014';//Check if current month and year

When i load the calendar without any events yet it looks like:

this jsfiddle

I hope someone could point me in the right direction of how to achieve what i try to do

HenryW
  • 3,551
  • 1
  • 23
  • 23

1 Answers1

0

It seems i answered my own question.

Should be something like:

Calendar.id = 'March 2014';//Check if current month and year

Generated HTML contains required values:

<div id="eventCalendarInline" data-current-year="2014" data-current-month="2">

in jQuery:

var currentYear= $('#eventCalendarInline').data("current-year");
var currentMonth = $('#eventCalendarInline').data("current-month");

    var Calendar = new Object();
    Calendar.month = currentMonth;
    Calendar.year  = currentYear;

And in php:

public function getEvents($calendar){               
    $sth = $this->dbh->prepare("SELECT * FROM events WHERE cyear = ? AND cmonth = ?");
    $sth->execute(array($calendar->year, $calendar->month));
    return json_encode($sth->fetchAll());
}
HenryW
  • 3,551
  • 1
  • 23
  • 23