Hi Everyone,
I m having trouble with using php and javascript date functions together.
I got a jquery based timetable script somewhere from internet and modified it according to my requirements. You can see the timetable live at http://reviewturn.com/work-shop/mattsmarttraining/
.
Now how the timetable works? It takes input from php mysql and creates icons on relevant dates. Input includes title, desc, date.
It working fine expect the date problem. Now if the input date is 2011-03-16, the icon will appear on 2011-04-16. In other words, it puts the icon on the same date of next month. This is the issue.
My code:
Let me know if anybody needs more details.Code:<script type='text/javascript'> var eventData = { events : [ <?php do { if($row_classes['class_type'] == "Circuit training"){ $classtype = "c"; } if($row_classes['class_type'] == "Boxing"){ $classtype = "b"; } if($row_classes['class_type'] == "Running"){ $classtype = "r"; } $id = $row_classes['class_id']; $date = $row_classes['cdate']; //echo $date; //$date = strtotime(date("Y,m,d", strtotime($date)). "-1 month"); $date = date('Y,m,d',strtotime($date)); //echo $date; $ctype = $row_classes['class_type']; $time = $row_classes['ctime']; $trainer = $row_classes['name']; $ocation = $row_classes['loc_name']; $places = $row_classes['Places']; if( !empty($prevdate) and $prevdate == $date){ $c++; if ($c == 1){ $stime = 00; $etime = 06;} if ($c == 2){ $stime = 06; $etime = 12;} if ($c == 3){ $stime = 12; $etime = 18;} if ($c == 4){ $stime = 18; $etime = 24;} }else{ $c == 1; $stime = 00; $etime = 06; } //$stime = 00; $etime = 06; $prevdate = $date; //echo $ocation; ?> {"id":'<?php echo $id; ?>', "start": new Date(<?php echo $date; ?>,<?php echo $stime; ?>), "end": new Date(<?php echo $date; ?>,<?php echo $etime; ?>),"title":'<h4><?php echo $ctype; ?> <strong><?php echo $time; ?></strong></h4><p><?php echo $ocation; ?></p><p>Trainer: <?php echo $trainer; ?> </p><p>Places: <?php echo $places; ?> </p><p><a href="reserve.php?classid=<?php echo $id; ?>" class="fly">Click to book now.</a></p>', "classtype":'<?php echo $classtype; ?>'}, <?php } while ($row_classes = mysql_fetch_assoc($classes)); ?> ] }; $(document).ready(function() { $('#calendar').weekCalendar({ date: new Date(), timeslotsPerHour: 1, height: function($calendar){ return $(window).height() - $("h1").outerHeight() - $(".description").outerHeight(); }, eventRender : function(calEvent, $event) { if(calEvent.end.getTime() < new Date().getTime()) { $event.css("backgroundColor", "#fff"); $event.find(".time").css({"backgroundColor": "#999", "border":"1px solid #888"}); } }, data:eventData }); });
Please tell me where I m coding wrong. I have spend night on it but still not successful. Please help.
Thanks in advance
Nabeel


Reply With Quote

Bookmarks