PDA

View Full Version : suggetions?


edbr
09-26-2008, 06:27 AM
i have a pet project i would like to make which is a booking calendar. Even though its way past my capabilities so far
I need it to shoe dates that are booked so i will need to make an admin area.
i was thinking this ;
if the calendar is displayed as a table i could make the cells a class which would change background colour depending on a given database value .
Does this sound realistic ? I will have to try and adapt a calendar script as I do not know how to make one , any one point me in a direction before i dig my self a nice deep hole fo the next few weekends?

davidj
09-26-2008, 01:23 PM
its a nice project that

i would use it to learn

get those PHP skills sharpened

i have never done anything with calandars in php but im willing to get stuck in to give you a hand

could do this bit together

rattlsnak
09-26-2008, 05:42 PM
Look at this one:

http://www.forsyth.k12.ga.us/wfhs/icalsw/calendar.asp?cal=em

I know its done in .ASP, but i would love to know how to do it in PHP. All the cells are clickable and different colors.

lux
09-26-2008, 07:07 PM
Ideal starting point to build a php calendar from Zend:

Build a calendar: http://www.zend.com/zend/trick/tricks-Oct-2002.php

Add links for months: http://www.zend.com/zend/trick/tricks-nov-2002.php



Includes excellent comments so you should be able to understand the code.

Enjoy!

rattlsnak
09-26-2008, 10:48 PM
thanks, ill be perusing that all weekend!

edbr
09-27-2008, 01:55 AM
great guys, i've been wnanting to try this for a while. I do have practicle uses for it but it is a leaning thing. My usual way is pull the wires out ans see if i can put them back, always a couple of screws left over though :)

edbr
09-27-2008, 03:53 AM
Ok that was easy i have the basic calendar now, thanks

edbr
09-30-2008, 05:28 AM
ok didnt get much further before getting stuck.
from this select statement $query = "SELECT dayofmonth(Date) as Date
FROM calendar WHERE month(Date) =
'$month' AND year(Date) = '$year'";

$result = mysql_query($query);
$dateArray = array();

while ($row = mysql_fetch_array($result)) {

$dateArray[] = $row['Date']; } i need to add field state so i can alter the class of the table based on the same criteria, i thought to just add, state to select from but obviously i am not understanding something. "dayofmonth(Date) as Date" confused me the filed is Date of course
i have attached a zip with the page, calendar and an .sql if anyone can help put me right .

I have a problem with display but 1 step at a time
476

edbr
10-03-2008, 07:29 AM
not doing to good here!
I started again as i could not get my head arround the date aray aspect of the zend calendar, so i first created the calendar layout as I wanted using a different class to create the calendars.
i used this to create 6 calendars in advance
$date=date("m");
$year=date("Y");

$next =date("m")+1;
$next2 =date("m")+2;
$next3 =date("m")+3;
$next4 =date("m")+4;
$next5 =date("m")+5;
then called them by
$myCelandar->showCalendar($year,$date);
$myCelandar->showCalendar($year,$next);
$myCelandar->showCalendar($year,$next2);
$myCelandar->showCalendar($year,$next3);
$myCelandar->showCalendar($year,$next4);
$myCelandar->showCalendar($year,$next5);
it looks ok displaying 2009 from january but if ! echo $next5 I get 15

in the class from what i can see each day is $actday, so i made a database with day,month and year fields.
currently it has some code to show todays date using this
if (($actday == $record['day']) && ($record['mon'] == $month) &&($record['year'] ==$year)) {
////echo "result";}

/// if (($actday == $today['mday']) && ($today['mon'] == $month)) {
$class = 'class="actday"'; ///class="actday"
}

My question is , am i correct in thinking that i would next select those 3 values and make them a condition against $actday? need some pointers as imat that 'why am i doing this?' stage

edbr
10-03-2008, 07:30 AM
class next post

edbr
10-03-2008, 07:35 AM
class Calendar{
function showCalendar($year=0,$month=0){

// Get today, reference day, first day and last day info
if (($year == 0) || ($month == 0)){
$referenceDay = getdate();
} else {
$referenceDay = getdate(mktime(0,0,0,$month,1,$year));
}
$firstDay = getdate(mktime(0,0,0,$referenceDay['mon'],1,$referenceDay['year']));
$lastDay = getdate(mktime(0,0,0,$referenceDay['mon']+1,0,$referenceDay['year']));
$today = getdate();


// Create a table with the necessary header informations
echo '<table class="month">';
echo ' <tr><th colspan="7">'.$referenceDay['month']." - ".$referenceDay['year']."</th></tr>";
echo ' <tr class="days"><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td><td>Su</td></tr>';


// Display the first calendar row with correct positioning
echo '<tr>';
if ($firstDay['wday'] == 0) $firstDay['wday'] = 7;
for($i=1;$i<$firstDay['wday'];$i++){
echo '<td>&nbsp;</td>';
}
$actday = 0;
for($i=$firstDay['wday'];$i<=7;$i++){
$actday++;



if (($actday == $record['day']) && ($record['mon'] == $month) &&($record['year'] ==$year)) {
////echo "result";}

/// if (($actday == $today['mday']) && ($today['mon'] == $month)) {
$class = 'class="actday"'; ///class="actday"
}

echo "<td$class>$actday</td>";



}
echo '</tr>';

//Get how many complete weeks are in the actual month
$fullWeeks = floor(($lastDay['mday']-$actday)/7);

for ($i=0;$i<$fullWeeks;$i++){
echo '<tr>';
for ($j=0;$j<7;$j++){
$actday++;



if (($actday == $record['day']) && ($record['mon'] == $month) &&($record['year'] ==$year)) {
////echo "result";}

/// if (($actday == $today['mday']) && ($today['mon'] == $month)) {
$class = 'class="actday"'; ///class="actday"
}
else {
$class = '';
}
echo "<td$class>$actday</td>";



}
echo '</tr>';
}

//Now display the rest of the month
if ($actday < $lastDay['mday']){
echo '<tr>';

for ($i=0; $i<7;$i++){
$actday++;



if (($actday == $record['day']) && ($record['mon'] == $month) &&($record['year'] ==$year)) {
////echo "result";}

/// if (($actday == $today['mday']) && ($today['mon'] == $month)) {
$class = 'class="actday'; ///"
}
else {
$class = '';
}

if ($actday <= $lastDay['mday']){
echo "<td$class>$actday</td>";
}
else {
echo '<td>&nbsp;</td>';
}




}


echo '</tr>';
}

echo '</table>';
}

}

davidj
10-03-2008, 11:07 AM
would be nice to have a class repository

edbr
10-04-2008, 05:26 AM
not that it works either but a mistake, should have been

($actday == $record['day']) && ($record['month'] == $month) && ($record['year'] ==$year)) {

edbr
10-04-2008, 05:55 AM
heres the whole thing so far, I'm off to do battle with it tomorrow
480