CalendarXP.net Support Forum Index CalendarXP.net Support
Most forums here are private and invisible to public.
 
 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to dynamically generate the agenda/events using PHP and MySQL?

 
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> CalendarXP F.A.Q.
View previous topic :: View next topic  
Author Message
calendarxp
Site Admin


Joined: 30 Jan 2005
Posts: 409

PostPosted: Wed Jan 25, 2006 2:51 am    Post subject: How to dynamically generate the agenda/events using PHP and MySQL? Reply with quote

1st, create a database table in MySQL with the following scripts:
Code:
CREATE TABLE `my_agenda` (                     
             `ag_year` smallint NOT NULL,       
             `ag_month` smallint NOT NULL,     
             `ag_day` smallint NOT NULL,       
             `ag_message` varchar(255) default '',     
             `ag_action` varchar(255) default '',       
             `ag_bgcolor` varchar(20) default 'null',     
             `ag_fgcolor` varchar(20) default 'null',     
             `ag_bgimg` varchar(255) default 'null',       
             `ag_boxit` varchar(20) default 'null',       
             `ag_html` varchar(255) default 'null',                               
             PRIMARY KEY  (`ag_year`,`ag_month`,`ag_day`) 
           )

2nd, create a file named agenda.php with the following contents:
Code:
<?
header("Content-Type: text/javascript");

$lnk=mysql_connect("<db_hostname>", "<db_user>", "<db_password>");
mysql_select_db("<db_name>",$lnk) or die( "Unable to select database");
$query="SELECT * FROM my_agenda";
$result=mysql_query($query);

$num=mysql_numrows($result);
mysql_close();

for ($i=0; $i < $num; $i++) {
$year=mysql_result($result,$i,"ag_year");
$month=mysql_result($result,$i,"ag_month");
$day=mysql_result($result,$i,"ag_day");
$msg=mysql_result($result,$i,"ag_message");
$action=mysql_result($result,$i,"ag_action");
$bgcolor=mysql_result($result,$i,"ag_bgcolor");
$fgcolor=mysql_result($result,$i,"ag_fgcolor");
$bgimg=mysql_result($result,$i,"ag_bgimg");
$boxit=mysql_result($result,$i,"ag_boxit");
$html=mysql_result($result,$i,"ag_html");
?>

fAddEvent(<?=$year?>,<?=$month?>,<?=$day?>,"<?=$msg?>","<?=$action?>",
"<?=$bgcolor?>","<?=$fgcolor?>","<?=$bgimg?>","<?=$boxit?>","<?=$html?>");

<?
}
?>
// -- you may append additional javascript here, e.g. fHoliday() --
Please remember to use the real db name, user id and password to replace the placeholders in above code.

Finally, upload the agenda.php to your web server (suppose it's placed at /php-cgi/agenda.php) and replace the agenda.js in the name and id of the <iframe> calendar tag with the full path to agenda.php:
Code:
<iframe name="gToday:normal:/php-cgi/agenda.php" name="gToday:normal:/php-cgi/agenda.php" ...>

Now put in some records in the db table and load up your page - you should see the agenda events showing up nicely in the calendar.

Note that you can still append the fHoliday() function, as in agenda.js, to the end of the agenda.php so as to retain the holidays. And in the agenda tutorial you may also find an example written in JSP code.

Last but not least, please be careful if you would like to use double-quote char (") in the strings - you should escape them wisely so as not to mess up the string boundary of javascript. If you were encountering any error, please point your browser directly to the URL of agenda.php, then either "view page source" or view the downloaded file - it should reveal the generated content. Make sure the content is pure valid javascript (no <script> tags allowed), as if it were in an agenda.js file.

_________________
Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> CalendarXP F.A.Q. All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Copyright 2003- Idemfactor Solutions, Inc. All rights reserved.
Powered by phpBB © 2001, 2005 phpBB Group