Jump to content

Calendar Help Arrays


adrian_fields

Recommended Posts

Hi All,

I am writing a calendar code using Keith Devens PHP Calendar (version 2.3).

What I am trying to acheive is this on one of my database tables I have a list of properties I have 41 property lists and each one has 2 sections for rates each section is named accordingly "a" for Jan for the first rate and "ma" for Jan for the second rate and there is 31 for each ie: a1 to a31 and ma1 to ma31 accordingly.

At any given time there can be a rate in any one of these fields what I am trying to do is pull a 12 month view calendar on screen which show all these rates to the corresponding date on the calendar.

The problem im having is with Keith Devens day Array() as ive never been too good with arrays.

The code I have is pulling the data but only the first one it hits and I need to put them all into the array.

I have included the code if someone can help I would appreciate it.

 

<?php
# PHP Calendar (version 2.3), written by Keith Devens
# http://keithdevens.com/software/php_calendar
#  see example at http://keithdevens.com/weblog
# License: http://keithdevens.com/software/license

function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()){
    $first_of_month = gmmktime(0,0,0,$month,1,$year);
    #remember that mktime will automatically correct if invalid dates are entered
    # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
    # this provides a built in "rounding" feature to generate_calendar()

    $day_names = array(); #generate all the day names according to the current locale
    for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
        $day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name

    list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
    $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
    $title   = htmlentities(ucfirst($month_name)).' '.$year;  #note that some locales don't capitalize month and day names

    #Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
    @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
    if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
    if($n) $n = ' <span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
    $calendar = '<table class="calendar" border="1">'."\n".
        '<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";

    if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
        #if day_name_length is >3, the full name of the day will be printed
        foreach($day_names as $d)
            $calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
        $calendar .= "</tr>\n<tr>";
    }

    if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'"> </td>'; #initial 'empty' days
    for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
        if($weekday == 7){
            $weekday   = 0; #start a new week
            $calendar .= "</tr>\n<tr>";
        }
        if(isset($days[$day]) and is_array($days[$day])){
            @list($link, $content2) = $days[$day];
            $content  = $day;
            $calendar .= '<td>'.
                ($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).$content2.'</td>';
        }
        else $calendar .= "<td>$day</td>";
    }
    if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

    return $calendar."</tr>\n</table>\n";
}


function set($month, $year)
{
$days = array();
$kez = 1;
$bef = 31;
		while($kez <= $bef)
		{	
			$k2 = $kez;

$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
mysql_connect("$host", "$username", "$password")or die("cannot connect");
if ($month == 1){$m = 'a'; $ma = 'ma';}
if ($month == 2){$m = 'b'; $ma = 'mb';}
if ($month == 3){$m = 'c'; $ma = 'mc';}
if ($month == 4){$m = 'd'; $ma = 'md';}
if ($month == 5){$m = 'e'; $ma = 'me';}
if ($month == 6){$m = 'f'; $ma = 'mf';}
if ($month == 7){$m = 'g'; $ma = 'mg';}
if ($month == {$m = 'h'; $ma = 'mh';}
if ($month == 9){$m = 'i'; $ma = 'mi';}
if ($month == 10){$m = 'j'; $ma = 'mj';}
if ($month == 11){$m = 'k'; $ma = 'mk';}
if ($month == 12){$m = 'l'; $ma = 'ml';}
$sql = "SELECT * FROM db213585521.property_list WHERE $m$k2 > 0 ";
$q = @mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($q);

$sql2 = "SELECT * FROM db213585521.property_list WHERE $ma$k2 > 0 ";
$q2 = @mysql_query($sql2) or die(mysql_error());
$row2 = mysql_fetch_array($q2);

if ($row[$m.$k2] > 0 || $row[$ma.$k2] > 0) {
if ($row[$m.$k2] > 0){
$code = $row['var'].'<br>£'.$row[$m.$k2].'<br>'; 
}else{$code = '';}
if ($row2[$ma.$k2] > 0){$code2 = $row2['var'].'<br>£'.$row2[$ma.$k2].'<br>';}else{$code2 ='';}
if($k2 != 0) $days[$k2] = array('', $code.$code2);
}

			$kez++;		

		}		
setlocale(LC_TIME, 'en_GB');
echo generate_calendar($year, $month, $days, 3, NULL); 
}
?>
<table style="margin: auto">

<tr>

    <?php for($month=1; $month<=12; $month++){ ?>

        <td style="vertical-align: top">

            <?php set($month, date('Y')); ?>

        </td>

        <?php if($month%4 == 0 and $month<12){ ?>

            </tr><tr>

        <?php } ?>

    <?php } ?>

</tr>

</table>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.