Loading the Calendar ~ Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples
Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples: Loading the Calendar

Loading the Calendar

The next part of your Ajax-powered calendar that is in need of updating is the calendar itself. Naturally, since you are dealing with a dynamically created task listing, it makes sense that the calendar should retrieve information from the database and load it into each day’s task listing. You can achieve such functionality by querying the database for existing records as it checks the calendar days. Consider the changes to taskchecker.php that will allow the system to identify any tasks on a given day:

<?php
//taskchecker.php
//Add in the database connector.
require_once ("dbconnector.php");
//Open the database.
$db = opendatabase();
//Set up the dynamic query string.
$querystr = "SELECT description FROM task WHERE thedate=➥
'" . addslashes ($_GET['thedate']) . "'";
if ($datequery = mysql_query ($querystr)){
if (mysql_num_rows ($datequery) > 0){
?>
<div style="width: 150px; background: #FFBC37; border-style: solid; ➥
border-color: #000000; border-width: 1px;">
<div style="padding: 10px;">
<?php
while ($datedata = mysql_fetch_array ($datequery)){
if (!get_magic_quotes_gpc()){
echo stripslashes ($datedata['description']);
} else {
echo $datedata['description'];
}
}
?>
</div>
</div>
<?php
}
} else {
echo mysql_error();
}
//Close the database connection.
mysql_close ($db);
?>

As you can see, you once again load in the database connector script and then call the opendatabase function. Once the database is open, it is a simple matter of creating a query that checks for any tasks that have been set up on each particular day. You then use the mysql_num_rows function to determine if a particular day has any tasks set up, and the while loop cycles through them with the mysql_fetch_array function to display all tasks. It is also important to clean up afterward. You do so by calling the mysql_close function, which will close the link to the database.




Related Posts by Categories

0 comments:

Useful Links on Adobe Flex

Your Ad Here

Latest Books on Adobe Flex