Fullcalendar

Hello

My problem is about events for calendar, precisely speaking i dont know how to dynamically add data for events

here is my code in view file


<div>

	

	<?php $message = Message::model()->findAll(); ?>

	<?php foreach($message as $messag): ?>

	<?php $names[] = $messag['contacts']; ?>

	<?php $date[] = $messag['send_datetime']; ?>

	<?php endforeach; ?>

</div>




<script>

$(document).ready(function() {


    // page is now ready, initialize the calendar...


    $('#calendar').fullCalendar({

			header: {

				left: 'prev,next today',

				center: 'title',

				right: 'month,agendaWeek,agendaDay'

			},

			events: [

			{	

				

				title: '<?php echo $names[0]; ?>',

				start: '<?php echo $date[0]; ?>',

				url: 'view/1'

			},

				{

				title: '<?php echo $names[1]; ?>',

				start: '<?php echo $date[1]; ?>',

				url: 'view/2'

			},

				{

				title: '<?php echo $names[2]; ?>',

				start: '<?php echo $date[2]; ?>',

				url: 'view/3'

			}

		]

    })

	$('#calendar').fullCalendar('changeView', 'agendaWeek');


});

</script>

<div id='calendar'>

	

</div>



i dont know how to code it in such a way that it will add as many events as i have data in database. i would be very grateful if someone could help