Monday, March 3, 2014

PHP Event Calendar (cont)

Php script to save created event  into database
data.php
<?php
$host = "localhost";
$username = "root";
$password = "";
mysql_connect($host,$username,$password);
mysql_select_db("calendar");

function getData(){
    $event = array();
    //------------------------------------edit here only-----------------------------------------------------
    $sql = "select * from event";
    //-------------------------------------------------------------------------------------------------------
    $query = mysql_query($sql);
    while($result = mysql_fetch_assoc($query)){
        $dt_start = mktime(0,0,0,date('m',strtotime($result['dt_start'])),date('d',strtotime($result['dt_start'])),date('Y',strtotime($result['dt_start'])));
        $dt_end = mktime(0,0,0,date('m',strtotime($result['dt_end'])),date('d',strtotime($result['dt_end'])),date('Y',strtotime($result['dt_end'])));
        $difference = $dt_end - $dt_start;
        $daysago = floor($difference /60/60/24);
       
        $i = 0;
        while ($i <= $daysago) {
            if ($i != 0) { $dt_start = $dt_start + 86400; }
            $today = date('Y-m-d',$dt_start);
            $day = date('dmY',strtotime($today));
            $event[$day][] = $result['event'];
           
            $i++;
        }
    }
    return $event;
}
function saveData($x){
    echo $sql = "insert into event "
            ."(event, dt_start, dt_end) "
            ."values "
            ."(".$x.")";
    return mysql_query($sql);
}
?>


Click links below to continue
css.php

4 comments:

  1. hi,
    thank you for your calendar it helps me a lot..
    i have a question to ask if you could help me, how to display the event details at the popup?
    for example, if i add event details such as time and place, how to display it in the calendar.php popup?
    thank you..

    ReplyDelete
    Replies
    1. you need to add a column at the table event to store place and add an input field for place

      Delete
    2. Thank you. I already did that but it(place data) didnt appear in the popup when pointer is hovered over the event name..

      Delete