<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>html tutorials &#124; css tutorials &#124; php tutorials &#124; Nodstrum Blog &#187; Javascript</title>
	<atom:link href="http://www.nodstrum.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nodstrum.com</link>
	<description>A coders playground.</description>
	<lastBuildDate>Wed, 23 Feb 2011 13:52:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>AutoCompleter Tutorial &#8211; jQuery(Ajax)/PHP/MySQL</title>
		<link>http://www.nodstrum.com/2007/09/19/autocompleter/</link>
		<comments>http://www.nodstrum.com/2007/09/19/autocompleter/#comments</comments>
		<pubDate>Wed, 19 Sep 2007 11:50:40 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/09/19/autocompleter/</guid>
		<description><![CDATA[AutoCompleter Tutorial As always, links to a demo and ZIP at the bottom, Enjoy! I thought i would write this tutorial because most of the auto completer applications i have seen just dump the code into a zip and tell you how to use it rather than how and why it works, knowing about this [...]]]></description>
			<content:encoded><![CDATA[<p><strong>AutoCompleter Tutorial</strong></p>
<p><em><strong>As always, links to a demo and ZIP at the bottom, Enjoy!</strong></em></p>
<p>I thought i would write this tutorial because most of the auto completer applications i have seen just dump the code into a zip and tell you how to use it rather than how and why it works, knowing about this enables you to customise it a lot more (this has been demonstrated with the other apps i have written here)!</p>
<p><img src="http://res.nodstrum.com/autoComplete/screenshots/AutoComplete_1.png" alt="" width="250" height="148" /><br />
<span id="more-44"></span><br />
And so we begin:<br />
<strong>JavaScript</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;script src=&quot;jquery-1.2.1.pack.js&quot; type=&quot;text/javascript&quot;&gt;&lt;!--mce:0--&gt;&lt;/script&gt;<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p><strong>JS Explaniation</strong></p>
<p>Ok, the above code it the guts to the script, this allows us to hook into the rpc.php file which carries out all the processing.</p>
<p>The Lookup function takes the word from the input box and POSTS it to the rpc.php page using the jQuery Ajax POST call.</p>
<p><strong>IF</strong> the inputString is &#8217;0&#8242; (Zero), it hides the suggestion box, naturally you would not want this showing if there is nothing in the text box. to search for.</p>
<p><strong>ELSE </strong>we take the &#8216;inputString&#8217;  and post it to the rpc.php page, the jQuery $.post() function is used as follows&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>callback<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>The &#8216;callback&#8217; part allows to hook in a function, this is where the real magic if thats what you can call it happens.</p>
<p><strong>IF</strong> the &#8216;data&#8217; returned length is more than zero (ie: there is actually something to show), show the suggestionBox and replace the HTML inside with the returned data.</p>
<p>SIMPLE!</p>
<p><strong>Now for the PHP Backend (RPC.php)</strong></p>
<p>As always my PHP Backend page is called rpc.php (Remote Procedure Call) not that it actually does that, but hey-ho.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// PHP5 Implementation - uses MySQLi.</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root'</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'autoComplete'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Show error if we cannot connect.</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'ERROR: Could not connect to the database.'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Is there a posted query string?</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'queryString'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'queryString'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Is the string length greater than 0?</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryString</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Run the query: We use LIKE '$queryString%'</span>
        <span style="color: #666666; font-style: italic;">// The percentage sign is a wild-card, in my example of countries it works like this...</span>
        <span style="color: #666666; font-style: italic;">// $queryString = 'Uni';</span>
        <span style="color: #666666; font-style: italic;">// Returned data = 'United States, United Kindom';</span>
&nbsp;
        <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT value FROM countries WHERE value LIKE '<span style="color: #006699; font-weight: bold;">$queryString</span>%' LIMIT 10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// While there are results loop through them - fetching an Object (i like PHP5 btw!).</span>
            <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span> <span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>fetch_object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// Format the results, im using</span>
	<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span> <span style="color: #b1b100;">for</span> the <span style="color: #990000;">list</span><span style="color: #339933;">,</span> you can change it<span style="color: #339933;">.</span>
                <span style="color: #666666; font-style: italic;">// The onClick function fills the textbox with the result.</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/li&gt;
	&lt;li onclick=&quot;fill('</span><span style="color: #0000ff;">'.$result-&amp;gt;value.'</span><span style="color: #0000ff;">');&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$result</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>value<span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/li&gt;
'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'ERROR: There was a problem with the query.'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Dont do anything.</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// There is a queryString.</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'There should be no direct access to this script!'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p><strong>PHP Explaination</strong></p>
<p>Im not going to go into much detail here because there are loads of comments in the code above.</p>
<p>Basically, it takes the  &#8216;QueryString&#8217; and does a query with a wildcard at the en.</p>
<p>This means that in this case of the code each key-press generates a new query, this is MySQL intensive if its always being done, but short of making it exceedingly complex it is fine for small scale applications.</p>
<p>The PHP code is the part you have to change to work in your system, and all the it is updating the &#8216;$query&#8217; to your database, you should be able to see where you put the table column name in etc&#8230;</p>
<p><strong>CSS Styling &#8211; im using CSS3, YEA BABY! much easier although limits the functionality to Firefox and Safari.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;!--
<span style="color: #6666ff;">.suggestionsBox</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#212427</span><span style="color: #00AA00;">;</span>
    -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span><span style="color: #00AA00;">;</span>
    -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.suggestionList</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.suggestionList</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">3px</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.suggestionList</span> li<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#659CD8</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
--<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>The CSS is pretty standard, nothing out of the ordinary.</p>
<p><strong>Main HTML</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&amp;lt;div&amp;gt;
&nbsp;
       &amp;lt;div&amp;gt;
&nbsp;
 			Type your county (for the demo):
&lt;input id=&quot;inputString&quot; onkeyup=&quot;lookup(this.value);&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
&nbsp;
 		&amp;lt;/div&amp;gt;			&amp;lt;div class=&quot;suggestionsBox&quot; id=&quot;suggestions&quot; style=&quot;display: none;&quot;&amp;gt;
&nbsp;
 			&lt;img style=&quot;position: relative; top: -12px; left: 30px;&quot; src=&quot;upArrow.png&quot; alt=&quot;upArrow&quot; /&gt;
&nbsp;
 			&amp;lt;div class=&quot;suggestionList&quot; id=&quot;autoSuggestionsList&quot;&amp;gt;
&nbsp;
&amp;lt;/div&amp;gt;
&nbsp;
 		&amp;lt;/div&amp;gt;
&nbsp;
&amp;lt;/div&amp;gt;</pre></div></div>

<p>That is the main bit of HTML, really all you need to run this is an input text box with the &#8216;onkeyup&#8217; function set to lookup(this.value); Also, i recommend NOT changing the ID of the input box, unless you change it in the Javascript section <img src='http://www.nodstrum.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Screenshots <img src='http://www.nodstrum.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </strong></p>
<p>I suppose you want to see some more screen shots&#8230;. OK.</p>
<p><img src="http://res.nodstrum.com/autoComplete/screenshots/AutoComplete_2.png" alt="" width="262" height="311" /></p>
<p>And another one!</p>
<p><img src="http://res.nodstrum.com/autoComplete/screenshots/AutoComplete_3.png" alt="" width="252" height="214" /></p>
<p><strong>And now for the links&#8230; this is probably what you are all looking for!</strong></p>
<p>Demo: <a href="http://res.nodstrum.com/autoComplete/">Auto Complete Demo</a></p>
<p>Source ZIP: <a href="http://www.2big2send.com/shared.php?token=76e263f7b764dde59f485e9c38430567">AutoComplete Source ZIP</a></p>
<p>If you need a domain to get you off your local test box buy <a href="http://www.networksolutions.com">domains</a> at Network Solutions!</p>
<p>If you have any problems, just post them up here (as comments) and i am sure i can help you fix it <img src='http://www.nodstrum.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks for the continued support,</p>
<p>Jamie.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/09/19/autocompleter/feed/</wfw:commentRss>
		<slash:comments>1318</slash:comments>
		</item>
		<item>
		<title>MySQL Calendar</title>
		<link>http://www.nodstrum.com/2007/06/27/mysql-calendar/</link>
		<comments>http://www.nodstrum.com/2007/06/27/mysql-calendar/#comments</comments>
		<pubDate>Wed, 27 Jun 2007 10:57:10 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/06/27/mysql-calendar/</guid>
		<description><![CDATA[VERSION 1.1 RELEASED! Changes: Added (by popular demand) Event deletion! Ok&#8230; I have finally got this script working! I have not done it like a tutorial because it is just too big, so here are a load of screen shots, There is a link to a fully functional demo and zip at the bottom! A [...]]]></description>
			<content:encoded><![CDATA[<p><strong>VERSION 1.1 RELEASED!</strong></p>
<p><em>Changes: Added (by popular demand) <strong>Event deletion</strong>! </em><br />
Ok&#8230; I have finally got this script working!</p>
<p>I have not done it like a tutorial because it is just too big, so here are a load of screen shots, <strong>There is a link to a fully functional demo and zip at the bottom!</strong></p>
<p><strong>A little setup information:</strong></p>
<p>1. Copy the entire calendar into whatever directory you want.</p>
<p>2. Create your database and import the &#8216;databaseSQL.sql&#8217; file into it, this will create the default data for running it.</p>
<p>3. Alter the &#8216;databaseConnection.php&#8217; file to show your connection details.That should be it..</p>
<p>NOTE:By default the username and password are both &#8216;<span style="font-weight: bold;">admin</span>&#8216; (without the quotes), i suggest you change your password in the control panel.</p>
<p>If you have any problems i will be happy to help, just post your query as a comment to this page.</p>
<p><strong>Screen Shots</strong></p>
<p><strong>Default View</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/defaultCalendar.png.png" alt="" /></p>
<p><span id="more-35"></span></p>
<p><strong>View Events</strong><br />
<img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/viewEvents.png" alt="" /></p>
<p><strong>View Events 2</strong><br />
<img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/noEvents.png" alt="" /></p>
<p><strong>Login</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/login.png" alt="" /></p>
<p><strong>Control Panel</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/controlPanel.png" alt="" /></p>
<p><strong>Add Event</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/addEvent1.png" alt="" /></p>
<p><strong>Add Event 2</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/addEvent2.png" alt="" /></p>
<p><strong>Downloads</strong></p>
<p><a href="http://res.nodstrum.com/mysqlCalendar/">MySQL Calendar V1.1 DEMO</a></p>
<p><a href="http://www.2big2send.com/shared.php?token=e3066c5a7376f9d83bfe3f1ae76e22a5">MySQL Calendar v1.1 ZIP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/06/27/mysql-calendar/feed/</wfw:commentRss>
		<slash:comments>292</slash:comments>
		</item>
		<item>
		<title>AJAX/PHP &#8211; the beginners guide to loading external content</title>
		<link>http://www.nodstrum.com/2007/02/27/ajaxcontentload/</link>
		<comments>http://www.nodstrum.com/2007/02/27/ajaxcontentload/#comments</comments>
		<pubDate>Tue, 27 Feb 2007 12:08:54 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/02/27/ajaxcontentload/</guid>
		<description><![CDATA[I&#8217;m going to assume that we all know, or have atleast heard of Prototype and script.aculo.us the two combine to form one powerful javascript library enabling developers to become designers (well, kind of). &#8211; Example and code at the bottom &#8211; I have created a ZIP file to get you up and running right away: [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to assume that we all know, or have atleast heard of <a href="http://prototype.conio.net" target="_blank">Prototype</a> and <a href="http://script.aculo.us" target="_blank">script.aculo.us</a> the two combine to form one powerful javascript library enabling developers to become designers (well, kind of).<br />
<strong>&#8211; Example and code at the bottom &#8211;</strong></p>
<p><strong>I have created a ZIP file to get you up and running right away: <a href="http://www.2big2send.com/shared.php?token=488b8b61350ef8bf1cdb75efd298de40">Download it now!</a></strong></p>
<p>I was showing a friend a few days ago something i made for a university module, Multimedia Applications Desgn (a mouthful i know). Basically we had to create a website promoting our group as a duo, thats all your getting about the project as its not really relevant and a tad embarrassing should anyone find the site!</p>
<p>There was a part of the site that my friend really liked and wanted to incorporate into his final year project&#8230; after sketching it out for him on paper i reconed that other people could benefit.<br />
This has probably been splashed everywhere, but i havent seen anything that incorporates all the same characteristics on <a href="http://digg.com" target="_blank">Digg</a>.</p>
<p>So here is a quick, hopefully easy to understand, tutorial of how its done.</p>
<p><strong>Abstract</strong><br />
We are trying to achieve loading content into a &#8216;div&#8217; element without refreshing the page, as well as showing a cool loading window inplace of the content as it is loading.</p>
<p><span id="more-11"></span></p>
<p><strong>Method</strong><br />
1 HTML page and 1 PHP page are required.<br />
You dont need to follow my method exactly as there are probably many many more out there, this is just my simple approach that seems to work.</p>
<p><strong>The HTML Page</strong><br />
This page will be the one we want the user to stay on with the &#8216;div&#8217; element in it for loading the content into.</p>
<p>Firstly we need to include the script.aculo.us javascript files.<br />
I just unzipped the script.aculo.us javascript files into my own folder called &#8216;js&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/lib/prototype.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/src/scriptaculous.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Next we need to create a few functions to make our life easier.<br />
The reason for this is it makes them reuseable and therfore we dont need to make our code look messy, im a little anal about code being correctly formatted and using the same chunks of code over and over again when they could simply be made into functions.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> startLoading<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// First we want to show the loading window then hide the content are we are loading into.</span>
  Element.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainAreaLoading'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Element.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainAreaInternal'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> finishLoading<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// First we want to show the content are, then toggle the loading window so it fades away.</span>
  Element.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainAreaInternel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// This happens 1 second after the mainAreaInternal is shown incase the content is still loading.</span>
  setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Effect.toggle('mainAreaLoading');&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> loadContent<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// We make use of the Ajax.Updater function to load the external data from our file.</span>
  <span style="color: #006600; font-style: italic;">// Start the loading window first by calling the function we made previously.</span>
  startLoading<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Request the content and update the 'div' area (i'll explain this in more detail later).</span>
  <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainAreaInternal'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'rpc.php'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span> postBody<span style="color: #339933;">:</span><span style="color: #3366CC;">'content='</span><span style="color: #339933;">+</span> id <span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Now finish the loading.</span>
  finishLoading<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next we have to make our &#8216;RPC file&#8217; (probably the wrong phrase to use, but it works for me).</p>
<p>Whatever you &#8216;echo&#8217; out to from this script will be what appears on the screen, html tags et-all, although i have found that outputting certain types of Javascript, like entire functions does not seem to work.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;">// We are posting our request, like the 'method=&quot;post&quot;' in a form, so we need to catch it.</span>
  <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// The content to show is determined by the $content integer we send through from the javascript.</span>
  <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'This is the content for the FIRST case statement!'</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Congratulations, you have loaded the second bit of content!'</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
      <span style="color: #666666; font-style: italic;">// This default case catches any $content value that does not have a case. I'm giving a nice error message so you can work out what went wrong.</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Whoops, there was a problem in the switch.You passed: &lt;em&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/em&gt; to the switch statement in rpc.php.'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end Content Switch.</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Here is the CSS Stylesheet to make all this possible</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">  <span style="color: #6666ff;">.mainAreaInternal</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#cccccc</span><span style="color: #00AA00;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #6666ff;">.mainAreaLoading</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Ok, now that the backend is all there, we need to do the difficult part (probably the easy bit for everyone else!), making the HTML page.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;span style=&quot;cursor: pointer;&quot; onclick=&quot;loadContent(1);&quot;&gt;Load Content 1&lt;/span&gt;
    &lt;span style=&quot;cursor: pointer;&quot; onclick=&quot;loadContent(2);&quot;&gt;Load Content 2&lt;/span&gt;
&nbsp;
&lt;!-- Navigation End --&gt;
&nbsp;
&nbsp;
 
&nbsp;
This is the content that will be visible at the very beginning.
&nbsp;
&lt;!-- End Main Area Internal --&gt;
&nbsp;
&nbsp;
&lt;span style=&quot;position: relative; top: 100px; left: 100px;&quot;&gt;
        Loading Please Wait...
      &lt;/span&gt;
&nbsp;
&lt;!-- End Main Area --&gt;</pre></div></div>

<p><strong>Now for the little explaination</strong><br />
Basically the loading &#8216;div&#8217; area is always there, it is just hidden from view, so when you call the &#8216;startLoading()&#8217; function it shows it, then hides it after the allotted time.<br />
Adding new &#8216;cases&#8217; to the rpc.php file will allow more content to be loaded <img src='http://www.nodstrum.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Example and Code</strong><br />
<a href="http://res.nodstrum.com/ajaxPHPContent/">Content Loading Example</a><br />
<a href="http://res.nodstrum.com/ajaxPHPContent/rpc.phps">RPC.php Source Code</a></p>
<p><a title="Get the Full Code in a ZIP Here" href="http://www.2big2send.com/shared.php?token=488b8b61350ef8bf1cdb75efd298de40">Get the Full Code in  a ZIP Here. </a></p>
<p>&#8211; If you are using this script, i would greatly appreciate it if you referenced http://nodstrum.com in your sourcecode <img src='http://www.nodstrum.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  &#8211;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/02/27/ajaxcontentload/feed/</wfw:commentRss>
		<slash:comments>165</slash:comments>
		</item>
		<item>
		<title>Calendar System &#8211; Easily using PHP &amp; Script.aculo.us</title>
		<link>http://www.nodstrum.com/2007/01/29/phpcalendar/</link>
		<comments>http://www.nodstrum.com/2007/01/29/phpcalendar/#comments</comments>
		<pubDate>Mon, 29 Jan 2007 21:37:48 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nodstrum.com/2007/01/29/phpcalendar/</guid>
		<description><![CDATA[THIS HAS BEEN UPDATED, PLEASE SEE THIS POST: http://nodstrum.com/2007/06/27/mysql-calendar/ Hi, Quite a few people seemed to like my previous tutorial Image Manipulation using PHP, and looking around many of the tutorial sites there are hardly any Calendar systems. Perfect, here is a simple, in calendar terms one&#8230; You&#8217;ll see what i mean. At the bottom [...]]]></description>
			<content:encoded><![CDATA[<p><strong>THIS HAS BEEN UPDATED, PLEASE SEE THIS POST: <a href="http://nodstrum.com/2007/06/27/mysql-calendar/">http://nodstrum.com/2007/06/27/mysql-calendar/</a></strong><a href="http://nodstrum.com/2007/06/27/mysql-calendar/"> </a></p>
<p>Hi,</p>
<p>Quite a few people seemed to like my previous tutorial <a href="http://nodstrum.com/2006/12/09/image-manipulation-using-php/">Image Manipulation using PHP</a>, and looking around many of the tutorial sites there are hardly any Calendar systems. Perfect, here is a simple, in calendar terms one&#8230;<br />
You&#8217;ll see what i mean.</p>
<p><strong>At the bottom of this tutorial there is a link to the ZIP and the test site. </strong></p>
<p>There are 3 main parts, the Javascript, the HTML and the PHP script.<br />
For this tutorial i am making it so you can change the date with the form and it will update the calendar without having to reload the entire page, AJAX style.</p>
<p>First we need the Script.aculo.us library, if you download my zip test file it is already included, but if not go to: http://script.aculo.us</p>
<p><span id="more-16"></span></p>
<p>This is the basic HTML page with the style sheet.<br />
The stylesheet is important because it contains the .calendarFloat part.<br />
The important part is the &lt; div id=&#8221;calendarInternal&#8221; &gt; this is where the calendar will be loaded into, its in its own &lt; div &gt; because we need to clear the float to enclose the calendar and make the box enclose the entire calendar.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&nbsp;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot; /&gt;
&lt;script src=&quot;js/lib/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/src/scriptaculous.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;style&gt;
	.calendarBox {
		position: relative;
		top: 30px;
		margin: 0 auto;
		padding: 5px;
		width: 254px;
		border: 1px solid #000;
	}
&nbsp;
	.calendarFloat {
		float: left;
		width: 31px;
		height: 25px;
		margin: 1px 0px 0px 1px;
		padding: 1px;
		border: 1px solid #000;
	}
&lt;/style&gt;
&lt;p id=&quot;calendar&quot; class=&quot;calendarBox&quot;&gt;&amp;nbsp;&lt;/p&gt;
&nbsp;
&lt;p id=&quot;calendarInternal&quot;&gt;
&nbsp;
&lt;br style=&quot;clear: both&quot; /&gt;</pre></div></div>

<p>Next is the Javascript that has to be added to the Head of the document.<br />
This does the highlighting and loading of the calendar using the script.aculo.us</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #003366; font-weight: bold;">function</span> highlightCalendarCell<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'1px solid #999999'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> resetCalendarCell<span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> color<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'1px solid #000000'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> startCalendar<span style="color: #009900;">&#40;</span>month<span style="color: #339933;">,</span> year<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'calendarInternal'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'rpc.php'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span> postBody<span style="color: #339933;">:</span><span style="color: #3366CC;">'action=startCalendar&amp;month='</span><span style="color: #339933;">+</span>month<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;year='</span><span style="color: #339933;">+</span>year<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The 2nd to last part is the RPC page, its not truly an RPC (remote procedure call) page, i just call it that because it is distinct.<br />
I use a switch statement because my function is normally enclosed in a huge page, so here goes.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
	<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'startCalendar'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'month'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'year'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$thisDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$thisDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;p style=&quot;margin-bottom: 3px&quot;&gt;&amp;nbsp;&lt;/p&gt;
&nbsp;
&lt;form name=&quot;changeCalendarDate&quot;&gt;
&lt;select id=&quot;ccMonth&quot; onchange=&quot;startCalendar($F('</span>ccMonth<span style="color: #0000ff;">'), $F('</span>ccYear<span style="color: #0000ff;">'))&quot;&gt;																																																																																																																																			&lt;option value=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$monthMaker</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/option&gt;										&lt;/select&gt;
&lt;select id=&quot;ccYear&quot; onchange=&quot;startCalendar($F('</span>ccMonth<span style="color: #0000ff;">'), $F('</span>ccYear<span style="color: #0000ff;">'))&quot;&gt;																																																																																																																																								&lt;option value=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/option&gt;										&lt;/select&gt;
&lt;/form&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Display the week days.</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Mon&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Tue&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Wed&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Thur&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #f0f2ff&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Fri&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #cccccc&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Sat&lt;/span&gt;&lt;/p&gt;
&nbsp;
&lt;p class=&quot;calendarFloat&quot; style=&quot;text-align: center; background-color: #cccccc&quot;&gt;&lt;span style=&quot;position: relative; top: 4px&quot;&gt;Sun&lt;/span&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Show the calendar.</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>date<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #339933;">,&gt;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$thisDay</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$finalDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thisDay</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$today</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$fdf</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$finalDate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thisDay</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$fdf</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Skip some cells to take into account for the weekdays.</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$firstDay</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fdf</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$skip</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$firstDay</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$skip</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$skip</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$s</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #000088;">$skip</span><span style="color: #339933;">;</span> <span style="color: #000088;">$s</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;/date(&quot;t&quot;,&gt;
&nbsp;
&lt;p class=&quot;calendarFloat&quot; style=&quot;border: 1px solid #ffffff&quot;&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Make the weekends a darker colour.</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$finalDate</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$finalDate</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$bgColor</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#CCC'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$bgColor</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#f0f2ff'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
             <span style="color: #666666; font-style: italic;">// == Add any database query here using $finalDate as the timestamp for this date.</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Display the day.</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&nbsp;
&lt;p class=&quot;calendarFloat&quot; id=&quot;calendarDay_'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$thisDay</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; style=&quot;cursor: pointer&quot;&gt;
&nbsp;
onMouseOver=&quot;highlightCalendarCell('</span>calendarDay_<span style="color: #0000ff;">'. $thisDay .'</span><span style="color: #0000ff;">')&quot;
									onMouseOut=&quot;resetCalendarCell('</span>calendarDay_<span style="color: #0000ff;">'. $thisDay .'</span><span style="color: #0000ff;">')&quot;&amp;gt;
						&lt;span style=&quot;position: relative; left: 1px&quot;&gt;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$thisDay</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>The final part is the one that ties it all together. This javascript is placed at the bottom of the page, within the &lt; body &gt; tags.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
		startCalendar<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Now for a short explaniation&#8230;<br />
If startCalendar(0,0) is called like so, with zeros, it defaults to the current month, if you have a look at the RPC file, at the top, you will notice there is a line that is if $month == 0 and $year == 0, then the date is date(&#8220;m&#8221;); (i think).</p>
<p>Next we are making the form for selecting the month and year, at the same time making the selected month and year (gotten by $month and $year) the current ones in the drop doen boxes.</p>
<p>Now we are just displaying the days of the week so the calendar is readable.<br />
Now the difficult part, determining the timestamp incase we want to use the database.<br />
Skipping some days to take into account days from the previous month, so the 1st of the month starts ont he proper week day, thats a tough one.<br />
Then its just spitting out the calendar.</p>
<p>And here is the Piece De Resistance, if you can call it that&#8230;<br />
<a href="http://res.nodstrum.com/calendar/" target="_blank">http://res.nodstrum.com/calendar/</a></p>
<p>And now for the downloads:<br />
<a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=6">Calendar System ZIP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nodstrum.com/2007/01/29/phpcalendar/feed/</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
	</channel>
</rss>

