Help building diary

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

Help building diary

Post by lloydie-t »

I needsome help buiding a diary. I am using an exist .php class to do this, but there is no mention of how to get the details of the events into a displayed date. So far from the diary view script I can produce the linked date array and the event array, but will I can show the day in the table cell I cannot get the event id and description in it. Is there some way of matching the array pointers so that the correct event id and description is shown?

date Array
(
[0] => 05
[1] => 6
[2] => 7
[3] => 17
[4] => 18
)



event Array
(
[0] => 3
[1] => 3
[2] => 3
[3] => 4
[4] => 4
)

calendar class:

Code: Select all

<?php 

function build_calendar($month,$year,$dateArray) { 

$daysOfWeek = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); 
$firstDayOfMonth = mktime (0,0,0,$month,1,$year); 
$numberDays = date ('t',$firstDayOfMonth); 
$dateComponents = getdate($firstDayOfMonth); 
$monthName = $dateComponents['month']; 
$dayOfWeek = $dateComponents['wday']; 

$calendar = "<table class='calendar'>"; 
//$calendar .= "<caption>$monthName, $year</caption>"; 
//$calendar .= "<tr>"; 

foreach($daysOfWeek as $day) { 
$calendar .= "<th class='header'>$day</th>"; 
} 

$currentDay = 1; 

$calendar .= "</tr><tr>";

if ($dayOfWeek > 0) { 
$calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>"; 
} 

while ($currentDay <= $numberDays) { 

if ($dayOfWeek == 7) { 

$dayOfWeek = 0; 
$calendar .= "</tr><tr>"; 

} 
//this is the bit i am looking at------------------------------------------------
if (in_array($currentDay,$dateArray)) { 
$date = "$year-$month-$currentDay"; 

$calendar .= "<td class='linkedday' width='150' height='75'> 
<a href='dwelcome.php?date=$date' 
class='calendarlink'>$currentDay</a><p>$cal_idArray</p></td>"; 
//---------------------------------------------------------------------------------

} else { 
$monthday = "$year-$month-$currentDay";
$calendar .= "<td class='day' width='150' height='75'>
<a href='dwelcome.php?date=$monthday' 
class='calendarlink'>$currentDay</a></td>"; 

} 

$currentDay++; 
$dayOfWeek++; 

} 

if ($dayOfWeek != 7) { 

$remainingDays = 7 - $dayOfWeek; 
$calendar .= "<td colspan='$remainingDays'>&nbsp;</td>"; 

} 

$calendar .= "</table>"; 

return $calendar; 

} 

?>
lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

Post by lloydie-t »

sorted it myself.

Code: Select all

if (in_array($currentDay,$dateArray)) { 
$date = "$year-$month-$currentDay"; 

include('connect.php');
$connection = @mysql_connect($host, $user, $pass) or die ("Unable to connect to database");
mysql_select_db($db) or die ("Unable to select database: $db ");
$query = "SELECT cal_id, cal_desc, cal_date_start, cal_date_end
FROM cal_entry
WHERE approved='Yes' AND cal_date_start <= '$date 23:59:59' AND cal_date_end >= '$date'
GROUP by cal_date_start ";
$queryResult = mysql_query($query);

while($row = mysql_fetch_assoc($queryResult)){
$ccal_id = $row["cal_id"];
$ccal_desc = $row["cal_desc"];
$ccal_date_start = $row["cal_date_start"];
$ccal_date_end = $row["cal_date_end"];}

$calendar .= "<td class='linkedday' width='150' height='75'> 
<a href='dwelcome.php?date=$date' 
class='calendarlink'>$currentDay</a><br>Start: $ccal_date_start <br>End: $ccal_date_end<br><font size="2"><a href='dwelcome.php?date=$ccal_id' 
class='calendarlink'>$ccal_desc</a></font></td>"; 

} else { 
$monthday = "$year-$month-$currentDay";
$calendar .= "<td class='day' width='150' height='75'>
<a href='dwelcome.php?date=$monthday' 
class='calendarlink'>$currentDay</a></td>"; 

}
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

amazing

Post by phpScott »

It is just amazing when that happens. Once you sit down to try and explain the problem to other people the fog lifts, the brain becomes unfuddled, and every thing seems so clear.

I know from experience that it is a wonderful feeling.

phpScott
Post Reply