<?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>Deaconsworld &#187; Code</title>
	<atom:link href="http://www.deaconsworld.org.uk/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deaconsworld.org.uk</link>
	<description>Welcome to my world</description>
	<lastBuildDate>Thu, 05 Feb 2009 09:41:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>WordPress style permalinks</title>
		<link>http://www.deaconsworld.org.uk/2008/08/06/wordpress-style-permalinks/</link>
		<comments>http://www.deaconsworld.org.uk/2008/08/06/wordpress-style-permalinks/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 08:48:44 +0000</pubDate>
		<dc:creator>Adam Deacon</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.deaconsworld.org.uk/2008/08/06/wordpress-style-permalinks/</guid>
		<description><![CDATA[Recently I was writing a database driven website, where all the content was within a database and the only real page was index.php.
This is easy enough to do, but of course, you need to tell index.php which page you want so you end up with URL like http://www.deaconsworld.org.uk/index.php?PageID=12 or  http://www.deaconsworld.org.uk/index.php?PageID=36. Not the most user or ]]></description>
			<content:encoded><![CDATA[<p>Recently I was writing a database driven website, where all the content was within a database and the only real page was index.php.</p>
<p>This is easy enough to do, but of course, you need to tell index.php which page you want so you end up with URL like http://www.deaconsworld.org.uk/index.php?PageID=12 or  http://www.deaconsworld.org.uk/index.php?PageID=36. Not the most user or SEO friendly. What I really wanted was URL that looked like this:  http://www.deaconsworld.org.uk/contact/ or http://www.deaconsworld.org.uk/about/</p>
<p><span id="more-98"></span>It turns out that it was actually quite simple. The principle behind it is to use a Apache re-write to redirect everything that isn&#8217;t a &#8216;real&#8217; page to index.php but leave the URI available for php to process.</p>
<p>Let&#8217;s say you have a database called tblPages that looks like this:</p>
<p><code>+-----------+-------------------------+------+-----+---------+----------------+<br />
| Field     | Type                    | Null | Key | Default | Extra          |<br />
+-----------+-------------------------+------+-----+---------+----------------+<br />
| PageID    | int(10) unsigned        | NO   | PRI | NULL    | auto_increment |<br />
| Title     | varchar(255)            | NO   |     | NULL    |                |<br />
| Content   | text                    | NO   |     | NULL    |                |<br />
+-----------+-------------------------+------+-----+---------+----------------+</code></p>
<p>Hopefully the table is self explanatory, The PageID is a unique number, Title is going to be the URL and Content is the HTML of the page.</p>
<p>Next you need a rewrite statement, this can either be put in the virtualhost declaration or in an .htaccess file. Again this would look like this:</p>
<p><code># Switch the rewrite Engine on<br />
RewriteEngine On<br />
# Set the base correctly<br />
RewriteBase /<br />
# Ignore and don't process any 'real' files or directories<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
# finally, rewrite everything else as index.php and stop processing<br />
RewriteRule . /index.php [L]</code></p>
<p>Next comes the magical bit. Although we can now type our URL in as http://www.deaconsworld.org.uk/contact/, Apache will send us to http://www.deaconsworld.org.uk/index.php. However, the $_SERVER[REQUEST_URI] will still contain http://www.deaconsworld.org.uk/contact/</p>
<p>Next we need to do a bit of work in PHP:</p>
<pre class="php">
PageID=GetPageID($_SERVER[REQUEST_URI]);

$SQL_GetPageInfo=mysql_query
	("SELECT Title,Content FROM tblPages WHERE PageID=$PageID");
$Details=mysql_fetch_array($SQL_GetPageInfo);

print $Details[Content];

function GetPageID($URI) {
	$PageTitle_array=explode('?', $URI);
	$PageTitle=$PageTitle_array[0];
	$PageTitle=rawurldecode($PageTitle);
	$PageTitle=trim($PageTitle, '/');
	$SQL_GetPageID=mysql_query
		("SELECT PageID from tblPages WHERE Title='$PageTitle'");
	return mysql_result($SQL_GetPageID,0);
}</pre>
<p>Again, the code should be pretty self explanatory.</p>
<p>So there you have it. The only things missing are a default page for when some enters http://www.deaconsworld.org.uk and to tidy up the security, but I&#8217;ll let you work that one out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deaconsworld.org.uk/2008/08/06/wordpress-style-permalinks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the load order of a webpage</title>
		<link>http://www.deaconsworld.org.uk/2007/04/23/changing-the-load-order-of-a-webpage/</link>
		<comments>http://www.deaconsworld.org.uk/2007/04/23/changing-the-load-order-of-a-webpage/#comments</comments>
		<pubDate>Mon, 23 Apr 2007 10:38:45 +0000</pubDate>
		<dc:creator>Adam Deacon</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.deaconsworld.org.uk/2007/04/23/changing-the-load-order-of-a-webpage/</guid>
		<description><![CDATA[I had an exciting weekend of writing a wonderful &#8216;webcast&#8217; system. Although it worked fine over the LAN, I found I had a problem when I uploaded it to the internet. The problem as a little weird. The system work by loading a bunch of images then used a version of 1pixelout&#8216;s mp3 flash player ]]></description>
			<content:encoded><![CDATA[<p>I had an exciting weekend of writing a wonderful &#8216;webcast&#8217; system. Although it worked fine over the LAN, I found I had a problem when I uploaded it to the internet. The problem as a little weird. The system work by loading a bunch of images then used a version of <a href="http://www.1pixelout.net/code/audio-player-wordpress-plugin/" target="_blank">1pixelout</a>&#8216;s mp3 flash player to play the audio. The problem I had was that half the images were loading, then the flash started loading. A user would then have to wait until the mp3 had finished playing before the final images were loaded.</p>
<p>I searched high and low on the net to see if there was a magical way to control the loading order. In the end I found this really elegant solution to load the flash as the last item.</p>
<p>In your style sheet, give the style you want to appear last: <code>display: none;</code>Then in the body tag change the display to block using onload:<code>document.getElementById('audio').style.display = 'block';"</code></p>
<p>I&#8217;ve tested this in Firefox and IE on both Linux and Windows and it seem to work perfectly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deaconsworld.org.uk/2007/04/23/changing-the-load-order-of-a-webpage/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lovely test data</title>
		<link>http://www.deaconsworld.org.uk/2007/04/17/lovely-test-data/</link>
		<comments>http://www.deaconsworld.org.uk/2007/04/17/lovely-test-data/#comments</comments>
		<pubDate>Tue, 17 Apr 2007 15:19:07 +0000</pubDate>
		<dc:creator>Adam Deacon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.deaconsworld.org.uk/2007/04/17/lovley-test-data/</guid>
		<description><![CDATA[I&#8217;ve spent most of my weekend thinking up names. Am I having a baby? NO! Do I need a killa handle for my next l33t project? No. Am I thinking of running away and setting up a new life for my self living in a tree? Yes, but that not why.
The reason I&#8217;ve been thinking ]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.deaconsworld.org.uk/datagenerator/" target="_blank"><img src="http://www.deaconsworld.org.uk/datagenerator/images/title.jpg" align="left" height="36" width="283" /></a>I&#8217;ve spent most of my weekend thinking up names. Am I having a baby? NO! Do I need a killa handle for my next l33t project? No. Am I thinking of running away and setting up a new life for my self living in a tree? Yes, but that not why.</p>
<p>The reason I&#8217;ve been thinking up new names is I&#8217;ve been testing my latest, greatest app and needed to fill it with test data. I hate thinking of test names. Normally I end up with bob, bob1, bob2 or my favourite piece of test data &#8220;rich is gay&#8221;. That&#8217;s fine if you just want a few test name, but what if you want say 1000 or 2000 or 10,000. That were   <a href="http://www.benjaminkeen.com">Benjamin Keen</a>&#8216;s Data Generator comes in. It&#8217;s a little script that create random data perfect for shoehorning in to any app you want. It will even output CSV, MySQL, XML, Excel or HTML and best of all it&#8217;s GNU</p>
<p>I&#8217;ve put a copy at <a href="http://www.deaconsworld.org.uk/datagenerator/" target="_blank">http://www.deaconsworld.org.uk/datagenerator/</a> to try and save him some bandwidth.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deaconsworld.org.uk/2007/04/17/lovely-test-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting Unix time to Time stamps</title>
		<link>http://www.deaconsworld.org.uk/2007/02/26/converting-unix-time-to-time-stamps/</link>
		<comments>http://www.deaconsworld.org.uk/2007/02/26/converting-unix-time-to-time-stamps/#comments</comments>
		<pubDate>Mon, 26 Feb 2007 11:08:43 +0000</pubDate>
		<dc:creator>Adam Deacon</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.deaconsworld.org.uk/2007/02/26/converting-unix-time-to-time-stamps/</guid>
		<description><![CDATA[I&#8217;ve been busy with a lot of time dependant code this week and working in Unix Time (number of seconds since epoch) has been making my brain go a bit squishy. Here a nice little code snippet for converting unixtime to a proper timestamp
perl -e 'print scalar localtime($ARGV[0]),"\n"' [unixtime] so: perl -e 'print scalar localtime($ARGV[0]),"\n"' ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been busy with a lot of time dependant code this week and working in Unix Time (number of seconds since epoch) has been making my brain go a bit squishy. Here a nice little code snippet for converting unixtime to a proper timestamp</p>
<p><code>perl -e 'print scalar localtime($ARGV[0]),"\n"' [unixtime]</code> so: <code>perl -e 'print scalar localtime($ARGV[0]),"\n"' 1172160024<br />
Thu Feb 22 16:00:24 2007</code></p>
<p>If you use this a lot, there&#8217;s nothing to stop you putting this in a nice little script, such as:</p>
<p><code>#!/bin/perl<br />
print scalar localtime($ARGV[0]),"\n"</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.deaconsworld.org.uk/2007/02/26/converting-unix-time-to-time-stamps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
