SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help in php calendar ??

    I am using this code for php calendar which is downloaed from http://www.drquincy.com

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Calendar</title>
    <style type="text/css" media="all">

        body {
       
            background-color: #2A2A2A;
            color: #EEEEEE;
            font-family: Tahoma, Verdana, sans-serif;
            font-size: 10px;
       
        }
       
        table {
       
            width: 125px;
       
        }
       
        td {
       
            padding: 1px;
            border: 1px solid #666666;
            text-align: center;
       
        }

    </style>
    </head>
    <body>
    <?php

        
    // get this month and this years as an int
        
    $thismonth = ( int ) date"m" );
        
    $thisyear date"Y" );
       
        
    // find out the number of days in the month
        
    $numdaysinmonth cal_days_in_monthCAL_GREGORIAN$thismonth$thisyear );
       
        
    // create a calendar object
        
    $jd cal_to_jdCAL_GREGORIANdate"m" ),date), date"Y" ) );
       
        
    // get the start day as an int (0 = Sunday, 1 = Monday, etc)
        
    $startday jddayofweek$jd );
       
        
    // get the month as a name
        
    $monthname jdmonthname$jd)

    ?>
    <table>
        <tr>
            <td colspan="7"><div align="center"><strong><?= $monthname ?></strong></div></td>
        </tr>
        <tr>
            <td><strong>S</strong></td>
            <td><strong>M</strong></td>
            <td><strong>T</strong></td>
            <td><strong>W</strong></td>
            <td><strong>T</strong></td>
            <td><strong>F</strong></td>
            <td><strong>S</strong></td>
        </tr>
        <tr>
    <?php

        
    // put render empty cells

        
    $emptycells 0;

        for( 
    $counter 0$counter <  $startday$counter ++ ) {
       
            echo 
    "\t\t<td>-</td>\n";
            
    $emptycells ++;
       
        }
       
        
    // renders the days
       
        
    $rowcounter $emptycells;
        
    $numinrow 7;
       
        for( 
    $counter 1$counter <= $numdaysinmonth$counter ++ ) {
       
            
    $rowcounter ++;
           
            echo 
    "\t\t<td>$counter</td>\n";
           
            if( 
    $rowcounter $numinrow == ) {
           
                echo 
    "\t</tr>\n";
               
                if( 
    $counter $numdaysinmonth ) {
               
                    echo 
    "\t<tr>\n";
               
                }
           
                
    $rowcounter 0;
           
            }
       
        }
       
        
    // clean up
        
    $numcellsleft $numinrow $rowcounter;
       
        if( 
    $numcellsleft != $numinrow ) {
       
            for( 
    $counter 0$counter $numcellsleft$counter ++ ) {
           
                echo 
    "\t\t<td>-</td>\n";
                
    $emptycells ++;
           
            }
       
        }

    ?>
        </tr>
    </table>
    </body>
    </html>
    I am using this calendar for the hotel booking system .
    The features to be added in the above calendar:

    I have to show those days of the month colorful(say orange) for those which have been booked but not processed and say red for those which have been processed by the admin as

    problem:
    suppose for the selected calendar, i have to show the colorful cells using database
    my database table is:
    booking
    id | booker_id | place | booking_from | booking_to | status
    Note: booking_from and booking_to field are in YY-MM-DD format..

    My problem is how to perform the required query to find the particular day is in the range of booking or not , if is in booking range then change the cell color else show the default color.
    Or do i have to use the other concept ..if yes please help
    I am waiting for your Help. I would be very greatful if i got my problem solved..
    Thanks in advance to all of you..

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Make a different CSS class in your CSS for each of the 3 options you have, normal, pending, processed. Each CSS class will show the day in a different colour.

    Before you display the calendar read the contents of your database for the month being displayed, then as you output the calendar pick the class you wish to show each day as.

    Hope it helps

    Terry
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply..
    What i actually want is
    My problem is how to perform the required query to find the particular day is in the range of booking or not
    in the above calendar generation code...

    Thanks in advance also..

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This should work

    Code:
     
    SELECT records FROM table WHERE datefield BETWEEN date('2007-01-01') AND date('2007-01-31');
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Plz help me a bit
    suppose i had the follwing table with values
    id booking_from booking_to status
    1 2007-02-08 2007-02-19 1
    2 2008-03-12 2008-03-29 1
    suppose for the month 2007-02 i had to show the days which has been booked in array..How to perform the query...

  6. #6
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, you need to have another table, that has a row for each day of each month, this will allow your query to return a row for each day between your selected dates. Then your query would look something like. Now I'm not a SQL'er, you may want to trot over to the SQL forum and ask the experts.

    Code:
     
    SELECT date FROM new_table 
    LEFT JOIN old_table
    ON MONTH(old_table.booking_from) = new_table.month
    WHERE selected_month BETWEEN old_table.booking_from & old_table.booking_to
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •