Welcome Guest, Not a member yet? Register   Sign In
Question about calendar and database
#1

[eluser]Mef[/eluser]
Hi,

I've got table with events in my database, where every event has date and time in DATETIME format.

What I'm trying to do, is to write a loop, to automatically fill CI's calendar array from db.

This is how it looks static:

Code:
$eventy = array(
               '2009' => array(
                    '02' => array(
                            6  => base_url().'repertuar/koncert/1',
                            7  => base_url().'repertuar/koncert/2',
                            13 => base_url().'repertuar/koncert/3',
                            20 => base_url().'repertuar/koncert/4',
                            21 => base_url().'repertuar/koncert/5',
                            27 => base_url().'repertuar/koncert/6'
                            ),
                    '03' => array(
                            6  => base_url().'repertuar/koncert/7',
                            7  => base_url().'repertuar/koncert/8',
                            13 => base_url().'repertuar/koncert/9',
                            20 => base_url().'repertuar/koncert/10',
                            27 => base_url().'repertuar/koncert/11',
                            28 => base_url().'repertuar/koncert/12'
                            ),
                    '04' => array(
                            3  => base_url().'repertuar/koncert/13',
                            5  => base_url().'repertuar/koncert/14',
                            17 => base_url().'repertuar/koncert/15',
                            24 => base_url().'repertuar/koncert/16'
                            ),
                    '05' => array(
                            8 => base_url().'repertuar/koncert/19',
                            15 => base_url().'repertuar/koncert/20',
                            22 => base_url().'repertuar/koncert/21',
                            23 => base_url().'repertuar/koncert/22',
                            29 => base_url().'repertuar/koncert/23',
                            30 => base_url().'repertuar/koncert/24'
                            ),
                    '06' => array(
                            5  => base_url().'repertuar/koncert/25',
                            13 => base_url().'repertuar/koncert/26',
                            19 => base_url().'repertuar/koncert/27'
                            )
                    )
                );

So basically I assume I need to pull out month and day from DATETIME field, create a loop and change static months, days and IDs to dynamic ones, but I have no idea how to achieve this. Any help will be appreciated.
#2

[eluser]Dam1an[/eluser]
You should be able to do this using PHPs date function.
Set the date format (the part you want) as the first parameter, and the date (in timestamp format) as the second parameter... That should get you what you want
#3

[eluser]Thorpe Obazee[/eluser]
if you have dates in datetime format, you can use strtotime then using what Dam1an suggested, date()
#4

[eluser]opel[/eluser]
I have this in my model :

Code:
function calendarDates($year, $month)
    {
        $query = $this->db->query(" SELECT blog_id, blog_title, blog_posted FROM blog WHERE YEAR(blog_posted) = ".$year." AND MONTH(blog_posted) = ".$month." ORDER BY blog_posted ASC");
        
        $dates = array();
        
        foreach ($query->result_array() as $key => $value)
        {
            $dates[$key] = $value;
        }
        
        return $dates;
    }

And this in my controller :

Code:
//Get article dates
        $dates = $this->blog_model->calendarDates($year, $month);
        
        //Create array for calendar
        
        foreach ($dates as $article)
        {
            //$calendar_dates[date("d",strtotime($article['posted']))] = base_url()."blog/month/".date("Y",strtotime($article['posted']))."/".date("d",strtotime($article['posted']))."/";

            $calendar_dates[date("j",strtotime($article['blog_posted']))] = base_url()."blog/article/".url_title($article['blog_title'])."/".$article['blog_id']."/";

        }
        

        return $this->calendar->generate($year, $month, $calendar_dates);
#5

[eluser]Mef[/eluser]
Thanks for replies. Opel, I'll try to adapt your code into my environment, special thanks for you for giving me some clues.




Theme © iAndrew 2016 - Forum software by © MyBB