Friday, 1 April 2011

Adding content to other pages

I have also started adding content to the other pages. Today I've added the content to the music page and wrote a review on the Running Trax 2 CD. I have also added a list of other CD's that are available to buy and linked them to play.com so people can go and purchase them for themselves if they want to.

Added a Calendar on the Events Page

Even though I was off ill I managed to add a calendar to my Events Page. I found a tutorial online and followed it and created the calendar in php. I then had help from Dave Carr to create the tables in php MyAdmin so I could add events to the calendar on the dates they where on. Dave created me a login and username and an admin page so I could update the calendar when events are on. Below are screenshots of the calendar:









So now when you click on the calendar say the 17th April 2011 if there is an event on that day a description will appear in a box under the calendar. So I know on Sun 17th April 2011 its the London Marathon because it appears when you click on the date.

PHP Code

to enable me to add events to the calendar I had to have some help from Dave Carr. Dave told me to create a table in phpMyAdmin and call it calTbl and add for fields to it called calID, calName, calDesc and calDate. Then give the calID and int(11) and add a value in the value box. Then in calName give it a varchar(65) and in the value box a name of the event. Then in the calDesc give it a varchar(255) and in the value box a description of the event and finally in the calDate in type make it date and then in the value box add the date for instance the date of the London Marathon would be 2011-04-17. So with Dave's help I created a calendar admin cms which I could add events to or edit an event or delete an event. To get into this admin cms I have a login and password.







Then to retrieve the information from the table on my site I had to enter the following code in Dreamweaver so the calendar would show on the site and you could click on a date and see what event was on. Below is the code I added to my events.php page.

Scheduled Events
Todays Date
//$todaysDate = date("n/j/Y");
//echo $todaysDate;
// Get values from query string
$day = (isset($_GET["day"])) ? $_GET['day'] : "";
$month = (isset($_GET["month"])) ? $_GET['month'] : "";
$year = (isset($_GET["year"])) ? $_GET['year'] : "";
//comparaters for today's date
//$todaysDate = date("n/j/Y");
//$sel = (isset($_GET["sel"])) ? $_GET['sel'] : "";
//$what = (isset($_GET["what"])) ? $_GET['what'] : "";

//$day = (!isset($day)) ? $day = date("j") : $day = "";
if(empty($day)){ $day = date("j"); }

if(empty($month)){ $month = date("n"); }

if(empty($year)){ $year = date("Y"); }
//set up vars for calendar etc
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
//$numEventsThisMonth = 0;
//$hasEvent = false;
//$todaysEvents = "";
//run a selec statement to hi-light the days
function hiLightEvt($eMonth,$eDay,$eYear){
//$tDayName = date("l");
$todaysDate = date("n/j/Y");
$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear;
if($todaysDate == $dateToCompare){
//$aClass = '' . $tDayName . '';
$aClass='class="today"';
}else{
//$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear;
//echo $todaysDate;
//return;
$sql="select count(calDate) as eCount from calTbl where calDate = '" . $eMonth . '/' . $eDay . '/' . $eYear . "'";
//echo $sql;
//return;
$result = mysql_query($sql);
while($row= mysql_fetch_array($result)){
if($row['eCount'] >=1){
$aClass = 'class="event"';
}elseif($row['eCount'] ==0){
$aClass ='class="normal"';
}
}
}
return $aClass;
}
?>
for($i = 1; $i < $numDays+1; $i++, $counter++){
$dateToCompare = $month . '/' . $i . '/' . $year;
$timeStamp = strtotime("$year-$month-$i");
//echo $timeStamp . '
';
if($i == 1){
// Workout when the first day of the month is
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++){
echo "
";
}
}
if($counter % 7 == 0){
?>
}
?>
}
?>
);">

);">
S
M
T
W
T
F
S
>
if(isset($_GET['v'])){
$date = $year.'-'.$month.'-'.$day;
$date = mysql_real_escape_string($date);
$sql="select calName,calDesc from calTbl where calDate = '$date'";
$result = mysql_query($sql);
$numRows = mysql_num_rows($result);
if($numRows == 0 ){
echo '

No Events

';
}else{
echo '

Events Listed

';
while($row = mysql_fetch_array($result)){
?>
}
}
}
?>