<?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>Tue, 04 May 2010 22:12:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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 enables you [...]]]></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" height="148" width="250" /><br />
 <span id="more-44"></span><br />
    And so we begin:<br />
<strong>JavaScript</strong></p>
<div class="dean_ch" style="white-space: wrap;">
&lt;script src=<span class="st0">&quot;jquery-1.2.1.pack.js&quot;</span> type=<span class="st0">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;&lt;script type=<span class="st0">&quot;text/javascript&quot;</span>&gt;</p>
<p><span class="kw2">function</span> lookup<span class="br0">&#40;</span>inputString<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>inputString.<span class="me1">length</span> == <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Hide the suggestion box.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#suggestions&#8217;</span><span class="br0">&#41;</span>.<span class="me1">hide</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $.<span class="me1">post</span><span class="br0">&#40;</span><span class="st0">&quot;rpc.php&quot;</span>, <span class="br0">&#123;</span>queryString: <span class="st0">&quot;&quot;</span>+inputString+<span class="st0">&quot;&quot;</span><span class="br0">&#125;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>data.<span class="me1">length</span> &gt;<span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#suggestions&#8217;</span><span class="br0">&#41;</span>.<span class="me1">show</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#autoSuggestionsList&#8217;</span><span class="br0">&#41;</span>.<span class="me1">html</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span> <span class="co1">// lookup</span></p>
<p><span class="kw2">function</span> fill<span class="br0">&#40;</span>thisValue<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#8216;#inputString&#8217;</span><span class="br0">&#41;</span>.<span class="me1">val</span><span class="br0">&#40;</span>thisValue<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;$<span class="br0">&#40;</span><span class="st0">&#8216;#suggestions&#8217;</span><span class="br0">&#41;</span>.<span class="me1">hide</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>&lt;/script&gt;</p></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 &#8216;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="dean_ch" style="white-space: wrap;">
$.<span class="me1">post</span><span class="br0">&#40;</span>url, <span class="br0">&#91;</span>data<span class="br0">&#93;</span>, <span class="br0">&#91;</span>callback<span class="br0">&#93;</span><span class="br0">&#41;</span></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="dean_ch" style="white-space: wrap;">
<span class="co1">// PHP5 Implementation &#8211; uses MySQLi. </span><br />
<span class="re0">$db</span> = <span class="kw2">new</span> mysqli<span class="br0">&#40;</span><span class="st0">&#8216;localhost&#8217;</span>, <span class="st0">&#8216;root&#8217;</span> ,<span class="st0">&#8221;</span>, <span class="st0">&#8216;autoComplete&#8217;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">if</span><span class="br0">&#40;</span>!<span class="re0">$db</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">// Show error if we cannot connect.</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;ERROR: Could not connect to the database.&#8217;</span>;<br />
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">// Is there a posted query string?</span><br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;queryString&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$queryString</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;queryString&#8217;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Is the string length greater than 0?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/strlen"><span class="kw3">strlen</span></a><span class="br0">&#40;</span><span class="re0">$queryString</span><span class="br0">&#41;</span> &gt;<span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Run the query: We use LIKE &#8216;$queryString%&#8217;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// The percentage sign is a wild-card, in my example of countries it works like this&#8230;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// $queryString = &#8216;Uni&#8217;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Returned data = &#8216;United States, United Kindom&#8217;;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$query</span> = <span class="re0">$db</span>-&gt;<span class="me1">query</span><span class="br0">&#40;</span><span class="st0">&quot;SELECT value FROM countries WHERE value LIKE &#8216;$queryString%&#8217; LIMIT 10&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$query</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// While there are results loop through them &#8211; fetching an Object (i like PHP5 btw!).</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$result</span> = <span class="re0">$query</span> -&gt;<span class="me1">fetch_object</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Format the results, im using &lt;li&gt; for the list, you can change it. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// The onClick function fills the textbox with the result.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;li onclick=&quot;fill(&#8216;</span><span class="st0">&#8216;.$result-&gt;value.&#8217;</span><span class="st0">&#8216;);&quot;&gt;&#8217;</span>.<span class="re0">$result</span>-&gt;<span class="me1">value</span>.<span class="st0">&#8216;&lt;/li&gt;&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;ERROR: There was a problem with the query.&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Dont do anything.</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="co1">// There is a queryString.</span><br />
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;There should be no direct access to this script!&#8217;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">?&gt;</span></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="dean_ch" style="white-space: wrap;">
&lt;style type=<span class="st0">&quot;text/css&quot;</span>&gt;</p>
<p><span class="re1">.suggestionsBox</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">position</span>: <span class="kw2">relative</span>;<br />
&nbsp; &nbsp; <span class="kw1">left</span>: <span class="re3">30px</span>;<br />
&nbsp; &nbsp; <span class="kw1">margin</span>: <span class="re3">10px</span> <span class="re3">0px</span> <span class="re3">0px</span> <span class="re3">0px</span>;<br />
&nbsp; &nbsp; <span class="kw1">width</span>: <span class="re3">200px</span>;<br />
&nbsp; &nbsp; <span class="kw1">background-color</span>: <span class="re0">#<span class="nu0">212427</span></span>;<br />
&nbsp; &nbsp; -moz-border-radius: <span class="re3">7px</span>;<br />
&nbsp; &nbsp; -webkit-border-radius: <span class="re3">7px</span>;<br />
&nbsp; &nbsp; <span class="kw1">border</span>: <span class="re3">2px</span> <span class="kw2">solid</span> <span class="re0">#<span class="nu0">000</span></span>;<br />
&nbsp; &nbsp; <span class="kw1">color</span>: <span class="re0">#fff</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.suggestionList</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">margin</span>: <span class="re3">0px</span>;<br />
&nbsp; &nbsp; <span class="kw1">padding</span>: <span class="re3">0px</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.suggestionList</span> li <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">margin</span>: <span class="re3">0px</span> <span class="re3">0px</span> <span class="re3">3px</span> <span class="re3">0px</span>;<br />
&nbsp; &nbsp; <span class="kw1">padding</span>: <span class="re3">3px</span>;<br />
&nbsp; &nbsp; <span class="kw1">cursor</span>: <span class="kw2">pointer</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.suggestionList</span> li<span class="re2">:hover</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">background-color</span>: <span class="re0">#659CD8</span>;<br />
<span class="br0">&#125;</span><br />
&lt;/style&gt;</div>
<p>The CSS is pretty standard, nothing out of the ordinary.</p>
<p><strong>Main HTML</strong></p>
<div class="dean_ch" style="white-space: wrap;">
&lt;div&gt;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp;&lt;div&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp; Type your county (for the demo):<br />
&lt;input size=&quot;30&quot; id=&quot;inputString&quot; onkeyup=&quot;lookup(this.value);&quot; type=&quot;text&quot; /&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;/div&gt;&nbsp; &nbsp; &nbsp; &lt;div class=&quot;suggestionsBox&quot; id=&quot;suggestions&quot; style=&quot;display: none;&quot;&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp; &lt;img src=&quot;upArrow.png&quot; style=&quot;position: relative; top: -12px; left: 30px&quot; alt=&quot;upArrow&quot; /&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp; &lt;div class=&quot;suggestionList&quot; id=&quot;autoSuggestionsList&quot;&gt;</p>
<p>&lt;/div&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;/div&gt;</p>
<p>&lt;/div&gt;</p></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" height="311" width="262" /></p>
<p>And another one!</p>
<p><img src="http://res.nodstrum.com/autoComplete/screenshots/AutoComplete_3.png" height="214" width="252" /></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://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=25">Auto Complete Demo</a></p>
<p>Source ZIP: <a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=26">AutoComplete Source ZIP</a></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>961</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[CSS]]></category>
		<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/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 little setup information:
1. [...]]]></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 class="Apple-style-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" /></p>
<p><span id="more-35"></span></p>
<p><strong>View Events</strong><br />
<img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/viewEvents.png" /></p>
<p><strong>View Events 2</strong><br />
<img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/noEvents.png" /></p>
<p><strong>Login</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/login.png" /></p>
<p><strong>Control Panel</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/controlPanel.png" /></p>
<p><strong>Add Event</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/addEvent1.png" /></p>
<p><strong>Add Event 2</strong></p>
<p><img src="http://res.nodstrum.com/mysqlCalendar/calendarScreenshots/addEvent2.png" /></p>
<p><strong>Downloads</strong></p>
<p><a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=22">MySQL Calendar V1.1 DEMO</a></p>
<p><a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=23">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>240</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: Download it [...]]]></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://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=24">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="dean_ch" style="white-space: wrap;">
&lt;script src=<span class="st0">&quot;js/lib/prototype.js&quot;</span> type=<span class="st0">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;<br />
&lt;script src=<span class="st0">&quot;js/src/scriptaculous.js&quot;</span> type=<span class="st0">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</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="dean_ch" style="white-space: wrap;">
<span class="kw2">function</span> startLoading<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="co1">// First we want to show the loading window then hide the content are we are loading into.</span><br />
&nbsp; Element.<span class="me1">show</span><span class="br0">&#40;</span><span class="st0">&#8216;mainAreaLoading&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; Element.<span class="me1">hide</span><span class="br0">&#40;</span><span class="st0">&#8216;mainAreaInternal&#8217;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">function</span> finishLoading<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="co1">// First we want to show the content are, then toggle the loading window so it fades away.</span><br />
&nbsp; Element.<span class="me1">show</span><span class="br0">&#40;</span><span class="st0">&#8216;mainAreaInternel&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="co1">// This happens 1 second after the mainAreaInternal is shown incase the content is still loading.</span><br />
&nbsp; setTimeout<span class="br0">&#40;</span><span class="st0">&quot;Effect.toggle(&#8216;mainAreaLoading&#8217;);&quot;</span>, <span class="nu0">1000</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">function</span> loadContent<span class="br0">&#40;</span>id<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="co1">// We make use of the Ajax.Updater function to load the external data from our file.</span><br />
&nbsp; <span class="co1">// Start the loading window first by calling the function we made previously.</span><br />
&nbsp; startLoading<span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; <span class="co1">// Request the content and update the &#8216;div&#8217; area (i&#8217;ll explain this in more detail later).</span><br />
&nbsp; <span class="kw2">new</span> Ajax.<span class="me1">Updater</span><span class="br0">&#40;</span><span class="st0">&#8216;mainAreaInternal&#8217;</span>, <span class="st0">&#8216;rpc.php&#8217;</span>, <span class="br0">&#123;</span>method: <span class="st0">&#8216;post&#8217;</span>, postBody:<span class="st0">&#8216;content=&#8217;</span>+ id +<span class="st0">&#8221;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; <span class="co1">// Now finish the loading.</span><br />
&nbsp; finishLoading<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></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="dean_ch" style="white-space: wrap;">
&nbsp; <span class="co1">// We are posting our request, like the &#8216;method=&quot;post&quot;&#8217; in a form, so we need to catch it.</span><br />
&nbsp; <span class="re0">$content</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;content&#8217;</span><span class="br0">&#93;</span>;</p>
<p>&nbsp; <span class="co1">// The content to show is determined by the $content integer we send through from the javascript.</span><br />
&nbsp; <span class="kw1">switch</span><span class="br0">&#40;</span><span class="re0">$content</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">case</span> <span class="nu0">1</span>:<br />
&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;This is the content for the FIRST case statement!&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;<br />
&nbsp; &nbsp; <span class="kw1">case</span> <span class="nu0">2</span>:<br />
&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;Congratulations, you have loaded the second bit of content!&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</p>
<p>&nbsp; &nbsp; <span class="kw2">default</span>:<br />
&nbsp; &nbsp; &nbsp; <span class="co1">// This default case catches any $content value that does not have a case. I&#8217;m giving a nice error message so you can work out what went wrong.</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;Whoops, there was a problem in the switch.You passed: &lt;em&gt;&#8217;</span>. <span class="re0">$content</span> .<span class="st0">&#8216;&lt;/em&gt; to the switch statement in rpc.php.&#8217;</span>;<br />
&nbsp; <span class="br0">&#125;</span> <span class="co1">// end Content Switch.</span><br />
<span class="kw2">?&gt;</span></div>
<p>Here is the CSS Stylesheet to make all this possible</p>
<div class="dean_ch" style="white-space: wrap;">
&nbsp; <span class="re1">.mainAreaInternal</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">position</span>: <span class="kw2">absolute</span>;<br />
&nbsp; &nbsp; <span class="kw1">top</span>: <span class="re3">40px</span>;<br />
&nbsp; &nbsp; <span class="kw1">left</span>: <span class="re3">0px</span>;<br />
&nbsp; &nbsp; <span class="kw1">width</span>: <span class="re3">500px</span>;<br />
&nbsp; &nbsp; <span class="kw1">height</span>: <span class="re3">300px</span>;<br />
&nbsp; &nbsp; <span class="kw1">background-color</span>: <span class="re0">#cccccc</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">overflow</span>: <span class="kw2">auto</span>;<br />
&nbsp; &nbsp; <span class="kw1">z-index</span>: <span class="nu0">0</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="re1">.mainAreaLoading</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">position</span>: <span class="kw2">absolute</span>;<br />
&nbsp; &nbsp; <span class="kw1">top</span>: <span class="re3">40px</span>;<br />
&nbsp; &nbsp; <span class="kw1">left</span>: <span class="re3">0px</span>;<br />
&nbsp; &nbsp; <span class="kw1">width</span>: <span class="re3">500px</span>;<br />
&nbsp; &nbsp; <span class="kw1">height</span>: <span class="re3">300px</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">z-index</span>: <span class="nu0">1</span>;<br />
&nbsp; <span class="br0">&#125;</span></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="dean_ch" style="white-space: wrap;">
&lt;p id=&quot;navigation&quot;&gt;</p>
<p>&lt;span style=&quot;cursor: pointer&quot; onclick=&quot;loadContent(1);&quot;&gt;Load Content 1&lt;/span&gt;<br />
&nbsp; &nbsp; &lt;span style=&quot;cursor: pointer&quot; onclick=&quot;loadContent(2);&quot;&gt;Load Content 2&lt;/span&gt;</p>
<p>&lt;!&#8211; Navigation End &#8211;&gt;<br />
&lt;p id=&quot;mainArea&quot;&gt; &lt;/p&gt;</p>
<p>&lt;p id=&quot;mainAreaInternal&quot; class=&quot;mainAreaInternal&quot;&gt;</p>
<p>This is the content that will be visible at the very beginning.</p>
<p>&lt;!&#8211; End Main Area Internal &#8211;&gt;</p>
<p>&lt;p id=&quot;mainAreaLoading&quot; class=&quot;mainAreaLoading&quot; style=&quot;display: none&quot;&gt;</p>
<p>&lt;span style=&quot;position: relative; top: 100px; left: 100px&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Loading Please Wait&#8230;<br />
&nbsp; &nbsp; &nbsp; &lt;/span&gt;</p>
<p>&lt;!&#8211; End Main Area &#8211;&gt;</p></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 &#8217;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://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=17">Content Loading Example</a><br />
<a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=18">RPC.php Source Code</a></p>
<p><a href="http://nodstrum.com/wp-content/plugins/DownloadCounter/download.php?id=24" title="Get the Full Code in a ZIP Here">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>133</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 of this tutorial [...]]]></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="dean_ch" style="white-space: wrap;">
<p>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot; /&gt;<br />
&lt;script src=&quot;js/lib/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;<br />
&lt;script src=&quot;js/src/scriptaculous.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;<br />
&lt;style&gt;<br />
&nbsp; .calendarBox {<br />
&nbsp; &nbsp; position: relative;<br />
&nbsp; &nbsp; top: 30px;<br />
&nbsp; &nbsp; margin: 0 auto;<br />
&nbsp; &nbsp; padding: 5px;<br />
&nbsp; &nbsp; width: 254px;<br />
&nbsp; &nbsp; border: 1px solid #000;<br />
&nbsp; }</p>
<p>&nbsp; .calendarFloat {<br />
&nbsp; &nbsp; float: left;<br />
&nbsp; &nbsp; width: 31px;<br />
&nbsp; &nbsp; height: 25px;<br />
&nbsp; &nbsp; margin: 1px 0px 0px 1px;<br />
&nbsp; &nbsp; padding: 1px;<br />
&nbsp; &nbsp; border: 1px solid #000;<br />
&nbsp; }<br />
&lt;/style&gt;<br />
&lt;p id=&quot;calendar&quot; class=&quot;calendarBox&quot;&gt; &lt;/p&gt;</p>
<p>&lt;p id=&quot;calendarInternal&quot;&gt;</p>
<p>&lt;br style=&quot;clear: both&quot; /&gt;</p></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="dean_ch" style="white-space: wrap;">
&lt;script type=<span class="st0">&quot;text/javascript&quot;</span>&gt;<br />
&nbsp; <span class="kw2">function</span> highlightCalendarCell<span class="br0">&#40;</span>element<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; $<span class="br0">&#40;</span>element<span class="br0">&#41;</span>.<span class="me1">style</span>.<span class="me1">border</span> = <span class="st0">&#8216;1px solid #999999&#8242;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw2">function</span> resetCalendarCell<span class="br0">&#40;</span>element, color<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; $<span class="br0">&#40;</span>element<span class="br0">&#41;</span>.<span class="me1">style</span>.<span class="me1">border</span> = <span class="st0">&#8216;1px solid #000000&#8242;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw2">function</span> startCalendar<span class="br0">&#40;</span>month, year<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">new</span> Ajax.<span class="me1">Updater</span><span class="br0">&#40;</span><span class="st0">&#8216;calendarInternal&#8217;</span>, <span class="st0">&#8216;rpc.php&#8217;</span>, <span class="br0">&#123;</span>method: <span class="st0">&#8216;post&#8217;</span>, postBody:<span class="st0">&#8216;action=startCalendar&amp;month=&#8217;</span>+month+<span class="st0">&#8216;&amp;year=&#8217;</span>+year+<span class="st0">&#8221;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
&lt;/script&gt;</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="dean_ch" style="white-space: wrap;">
<p>&nbsp; <span class="re0">$action</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;action&#8217;</span><span class="br0">&#93;</span>;<br />
&nbsp; <span class="kw1">switch</span><span class="br0">&#40;</span><span class="re0">$action</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; <span class="kw1">case</span> <span class="st0">&#8217;startCalendar&#8217;</span>:<br />
&nbsp; &nbsp; <span class="re0">$month</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;month&#8217;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; <span class="re0">$year</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;year&#8217;</span><span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$month</span> == <span class="nu0">0</span><span class="br0">&#41;</span> || <span class="br0">&#40;</span><span class="re0">$year</span> == <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="re0">$thisDate</span> = <a href="http://www.php.net/mktime"><span class="kw3">mktime</span></a><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;m&quot;</span><span class="br0">&#41;</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;d&quot;</span><span class="br0">&#41;</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;Y&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="re0">$thisDate</span> = <a href="http://www.php.net/mktime"><span class="kw3">mktime</span></a><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$month</span>, <span class="nu0">1</span>, <span class="re0">$year</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;<br />
&lt;p style=&quot;margin-bottom: 3px&quot;&gt; &lt;/p&gt;</p>
<p>&lt;form name=&quot;changeCalendarDate&quot;&gt;<br />
&lt;select id=&quot;ccMonth&quot; onchange=&quot;startCalendar($F(&#8216;</span>ccMonth<span class="st0">&#8216;), $F(&#8216;</span>ccYear<span class="st0">&#8216;))&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=&quot;&#8217;</span>. <span class="re0">$i</span> .<span class="st0">&#8216;&quot;&gt;&#8217;</span>. <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;F&quot;</span>, <span class="re0">$monthMaker</span><span class="br0">&#41;</span> .<span class="st0">&#8216;&lt;/option&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/select&gt;<br />
&lt;select id=&quot;ccYear&quot; onchange=&quot;startCalendar($F(&#8216;</span>ccMonth<span class="st0">&#8216;), $F(&#8216;</span>ccYear<span class="st0">&#8216;))&quot;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=&quot;&#8217;</span>. <span class="re0">$i</span> .<span class="st0">&#8216;&quot;&gt;&#8217;</span>. <span class="re0">$i</span> .<span class="st0">&#8216;&lt;/option&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/select&gt;<br />
&lt;/form&gt;</p>
<p>&#8216;</span>;</p>
<p>&nbsp; &nbsp; <span class="co1">// Display the week days.</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;<br />
&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;<br />
&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;<br />
&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;<br />
&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;<br />
&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;<br />
&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;</p>
<p>&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;</p>
<p>&#8216;</span>;</p>
<p>&nbsp; &nbsp; <span class="co1">// Show the calendar.</span><br />
&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$i</span>=<span class="nu0">0</span>; <span class="re0">$i</span>&lt;date<span class="br0">&#40;</span><span class="st0">&quot;t&quot;</span>,&gt;<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="re0">$thisDay</span> = <span class="br0">&#40;</span><span class="re0">$i</span> + <span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$month</span> == <span class="nu0">0</span><span class="br0">&#41;</span> || <span class="br0">&#40;</span><span class="re0">$year</span> == <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$finalDate</span> = <a href="http://www.php.net/mktime"><span class="kw3">mktime</span></a><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;m&quot;</span><span class="br0">&#41;</span>, <span class="re0">$thisDay</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;Y&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$today</span> = <a href="http://www.php.net/mktime"><span class="kw3">mktime</span></a><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;m&quot;</span><span class="br0">&#41;</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;d&quot;</span><span class="br0">&#41;</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;Y&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$fdf</span> = <a href="http://www.php.net/mktime"><span class="kw3">mktime</span></a><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;m&quot;</span><span class="br0">&#41;</span>, <span class="nu0">1</span>, <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;Y&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$month</span> = <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;m&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$year</span> = <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;Y&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$finalDate</span> = <a href="http://www.php.net/mktime"><span class="kw3">mktime</span></a><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$month</span>, <span class="re0">$thisDay</span>, <span class="re0">$year</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$fdf</span> = <a href="http://www.php.net/mktime"><span class="kw3">mktime</span></a><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$month</span>, <span class="nu0">1</span>, <span class="re0">$year</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; <span class="co1">// Skip some cells to take into account for the weekdays.</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$i</span> == <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$firstDay</span> = <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;w&quot;</span>, <span class="re0">$fdf</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$skip</span> = <span class="br0">&#40;</span><span class="re0">$firstDay</span> &#8211; <span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$skip</span> &lt; <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="re0">$skip</span> = <span class="nu0">6</span>; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$s</span>=<span class="nu0">0</span>; <span class="re0">$s</span>&lt;<span class="re0">$skip</span>; <span class="re0">$s</span>++<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;<br />
&lt;/date(&quot;t&quot;,&gt;</p>
<p>&lt;p class=&quot;calendarFloat&quot; style=&quot;border: 1px solid #ffffff&quot;&gt;</p>
<p>&#8216;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; <span class="co1">// Make the weekends a darker colour.</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="br0">&#40;</span><a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;w&quot;</span>, <span class="re0">$finalDate</span><span class="br0">&#41;</span> == <span class="nu0">0</span><span class="br0">&#41;</span> || <span class="br0">&#40;</span><a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;w&quot;</span>, <span class="re0">$finalDate</span><span class="br0">&#41;</span> == <span class="nu0">6</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$bgColor</span> = <span class="st0">&#8216;#CCC&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$bgColor</span> = <span class="st0">&#8216;#f0f2ff&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// == Add any database query here using $finalDate as the timestamp for this date.</span></p>
<p>&nbsp; &nbsp; &nbsp; <span class="co1">// Display the day.</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;</p>
<p>&lt;p class=&quot;calendarFloat&quot; id=&quot;calendarDay_&#8217;</span>. <span class="re0">$thisDay</span> .<span class="st0">&#8216;&quot; style=&quot;cursor: pointer&quot;&gt;</p>
<p>onMouseOver=&quot;highlightCalendarCell(&#8216;</span>calendarDay_<span class="st0">&#8216;. $thisDay .&#8217;</span><span class="st0">&#8216;)&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onMouseOut=&quot;resetCalendarCell(&#8216;</span>calendarDay_<span class="st0">&#8216;. $thisDay .&#8217;</span><span class="st0">&#8216;)&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span style=&quot;position: relative; left: 1px&quot;&gt;&#8217;</span>. <span class="re0">$thisDay</span> .<span class="st0">&#8216;&lt;/span&gt;</p>
<p>&#8216;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">break</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p><span class="kw2">?&gt;</span></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="dean_ch" style="white-space: wrap;">
&lt;script type=<span class="st0">&quot;text/javascript&quot;</span>&gt;<br />
&nbsp; &nbsp; startCalendar<span class="br0">&#40;</span><span class="nu0">0</span>,<span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &lt;/script&gt;</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>45</slash:comments>
		</item>
	</channel>
</rss>
