<?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/"
	>

<channel>
	<title>James Crooke - Web Developer</title>
	<atom:link href="http://www.jamescrooke.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jamescrooke.co.uk</link>
	<description>James' blog about games, programming, web development and other aspects of computing.</description>
	<pubDate>Fri, 01 May 2009 11:48:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introducing &#8220;What&#8217;s On?&#8221;</title>
		<link>http://www.jamescrooke.co.uk/blog/63/introducing-whats-on/</link>
		<comments>http://www.jamescrooke.co.uk/blog/63/introducing-whats-on/#comments</comments>
		<pubDate>Fri, 01 May 2009 11:48:51 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[betavine widget competition]]></category>

		<category><![CDATA[tv schedules]]></category>

		<category><![CDATA[whatson]]></category>

		<guid isPermaLink="false">http://www.jamescrooke.co.uk/?p=63</guid>
		<description><![CDATA[Last night I put the finishing touches to my mobile phone widget What&#8217;s On?.
The widget collects TV data feeds for all (well, most - 237) UK TV channels currently broadcasting today.  Using the widget, you can select your desired channel and date to view the schedule for your selection.  The widget also allows [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I put the finishing touches to my mobile phone widget <strong><a href="http://w0t.info/">What&#8217;s On?</a></strong>.</p>
<p>The widget collects TV data feeds for all (well, most - 237) UK TV channels currently broadcasting today.  Using the widget, you can select your desired channel and date to view the schedule for your selection.  The widget also allows you to send a link to the programme details to yourself or a friend - it also gives you the Sky+ code if you want to record it remotely via your mobile phone.  You can also keep track of your favourite channels by adding them to your favourites list.</p>
<p>This widget was created for the <a href="http://www.betavine.net/bvportal/competition/view.html?id=ff8080811f1f3dbb011f3721070438d1">Betavine Widget Competition 2009</a> which is being ran by Vodafone.  The first prize is a cool £20k, so I thought why not have a crack at that!</p>
<p>You can download/view the &#8220;What&#8217;s On?&#8221; application at <a href="http://w0t.info/">http://w0t.info/</a>, Iphone users can view the widget via <a href="http://whatson.forbsoft.com/">http://whatson.forbsoft.com/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamescrooke.co.uk/blog/63/introducing-whats-on/feed/</wfw:commentRss>
		</item>
		<item>
		<title>I&#8217;m a Millionaire!</title>
		<link>http://www.jamescrooke.co.uk/blog/53/im-a-millionaire/</link>
		<comments>http://www.jamescrooke.co.uk/blog/53/im-a-millionaire/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 13:28:52 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[Random]]></category>

		<category><![CDATA[dnscoop]]></category>

		<category><![CDATA[millionaire]]></category>

		<guid isPermaLink="false">http://www.jamescrooke.co.uk/?p=53</guid>
		<description><![CDATA[According to www.dnscoop.com I&#8217;m a millionaire.  Sadly, it isn&#8217;t quite true&#8230;..yet.
Today, they value my domain www.cj-design.com at no less than $5,089,906 (just shy of £3.7 million quid) due to it&#8217;s popularity, number of links, Alexa ranking and several other factors.
If anyone would like to buy it, I am open to offers in the £2,800,000 [...]]]></description>
			<content:encoded><![CDATA[<p>According to <a href="http://www.dnscoop.com">www.dnscoop.com</a> I&#8217;m a <strong>millionaire</strong>.  Sadly, it isn&#8217;t quite true&#8230;..yet.</p>
<p>Today, they value my domain <a href="http://www.cj-design.com">www.cj-design.com</a> at no less than $5,089,906 (just shy of £3.7 million quid) due to it&#8217;s popularity, number of links, Alexa ranking and several other factors.</p>
<p>If anyone would like to buy it, I am open to offers in the £2,800,000 to £3,200,000 range, this offer will expire in 28 days time, subject to terms and conditions; this does not affect your statutory rights.</p>
<div style="height: 130px; width: 119px; text-align: center; padding: 10px 0 10px 0; background: url(http://www.dnscoop.com/images/sharebgb.gif) no-repeat;">
<div style="border-bottom: solid 1px #cdcdcd; width: 100px; margin-bottom: 5px; padding-bottom: 5px;"><a style="font-size: 11px; font-family: arial;" title="Domain name appraisal" href="http://www.dnscoop.com/?site=www.cj-design.com">My Site is worth</a><br />
<span style="font-size: 12px; font-family: arial;"> <strong>$5,089,906</strong></span></div>
<div style="line-height:11px;font-family: 'Trebuchet MS',Arial,Verdana,Helvetica,sans-serif;"><a style="color:#444343;text-decoration:none;font-size:11px;" href="http://www.dnscoop.com">How much is<br />
your site worth?</a></div>
<p> </p></div>
<p>$5 million my arse.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamescrooke.co.uk/blog/53/im-a-millionaire/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cron for Windows IIS</title>
		<link>http://www.jamescrooke.co.uk/blog/10/cron-for-windows-iis/</link>
		<comments>http://www.jamescrooke.co.uk/blog/10/cron-for-windows-iis/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 12:25:34 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[Featured]]></category>

		<category><![CDATA[Servers]]></category>

		<category><![CDATA[cron]]></category>

		<category><![CDATA[iis]]></category>

		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.jamescrooke.co.uk/?p=10</guid>
		<description><![CDATA[This is a slightly updated repost of an article I wrote on my old blog. I have had a few requests from people and one from birf to put it back up so here it is;
First, a lesson in the real implementation of cron&#8230;
The crontab command, found in Unix operating systems, is used to schedule [...]]]></description>
			<content:encoded><![CDATA[<p>This is a slightly updated repost of an article I wrote on my old blog. I have had a few requests from people and one from <a href="http://www.mackney.com/">birf</a> to put it back up so here it is;</p>
<p>First, a lesson in the real implementation of cron&#8230;</p>
<p>The crontab command, found in Unix operating systems, is used to schedule commands to be executed periodically. It reads commands and collects them into a file also known as a &#8220;crontab&#8221; which is later read by the operating system which carries out the instructions contained within.</p>
<p>One of the most useful cron commands, particularly from a web developers point of view, is the ability to call up a webpage silently, in the background, at intervals or at a specified time. Think of the possibilites:</p>
<ul>
<li>Running a routine check on users in a database (deleting inactive accounts for example)</li>
<li>Scheduling an email, several days after a user has purchased an item from a site</li>
<li>Checking a site is functioning correctly</li>
</ul>
<p><strong>So how can you get Windows to perform cron-like tasks?<br />
</strong><br />
It&#8217;s <em>very</em> simple once you know how - which I do, you&#8217;ll be happy to read. You have probably found that several web sites offer programs that cost around £50 that promise to emulate cron.</p>
<p><strong>Don&#8217;t bother</strong>; especially if all you want to do is call up a web address.</p>
<p>This is how you do it…</p>
<ul>
<li>Download wget (<a href="http://web.archive.org/web/20070708041958/http://gnuwin32.sourceforge.net/packages/wget.htm">GnuWin32</a> is a good, clean, harmless one)</li>
<li>Install wget</li>
<li>Fire up the command line (Start &gt; Run &gt; then type “cmd”)</li>
<li>Run a command as shown below:</li>
</ul>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">schtasks /create /tn &quot;Test Cron&quot; /tr &quot;C:wget.exe http://www.site.com/cron.asp&quot; /sc minute /mo 5 /ru &quot;System&quot;</div></td></tr></tbody></table></div>
<p>Where</p>
<p>&#8220;Test Cron&#8221; is the name of your cron job (useful for reference purposes)<br />
&#8220;C:wget.exe&#8221; is the location of the wget.exe file<br />
<a href="http://www.site.com/cron.asp">http://www.site.com/cron.asp</a> is the URL for wget to fetch</p>
<p><strong>More Examples</strong></p>
<p>Let&#8217;s take a look at some more examples, that way you will understand the different options available&#8230;</p>
<p>Run a cron job every week</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">schtasks /create /tn &quot;Test Cron&quot; /tr &quot;C:wget.exe http://www.site.com/cron.asp&quot; /sc weekly /ru &quot;System&quot;</div></td></tr></tbody></table></div>
<p>Run a cron every week on a Friday</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">schtasks /create /tn &quot;Test Cron&quot; /tr &quot;C:wget.exe http://www.site.com/cron.asp&quot; /sc weekly /d FRI /ru &quot;System&quot;</div></td></tr></tbody></table></div>
<p>Run a cron every friday at 11:00am</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">schtasks /create /tn &quot;Test Cron&quot; /tr &quot;C:wget.exe http://www.site.com/cron.asp&quot; /sc weekly /st 11:00:00 /d FRI /ru &quot;System&quot;</div></td></tr></tbody></table></div>
<p>Run a cron every day at 17:00pm</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">schtasks /create /tn &quot;Test Cron&quot; /tr &quot;C:wget.exe http://www.site.com/cron.asp&quot; /sc daily /st 17:00:00 /ru &quot;System&quot;</div></td></tr></tbody></table></div>
<p>Run a cron every hour, on the hour</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">schtasks /create /tn &quot;Test Cron&quot; /tr &quot;C:wget.exe http://www.site.com/cron.asp&quot; /sc hourly /st 00:00:00 /ru &quot;System&quot;</div></td></tr></tbody></table></div>
<p><strong>So what&#8217;s happening exactly?</strong></p>
<p>Well as you might have guessed, all you&#8217;re doing is utilising Windows&#8217; &#8220;Scheduled Tasks&#8221; program - using a command line interface, which I actually find easier to use than the Scheduled Task UI. If you have installed wget and ran one of the commands above, you will be able to see your cron in action by going to &#8220;Start &gt; Programs &gt; Accessories &gt; System Tools &gt; Scheduled Tasks&#8221;.</p>
<p>And of course, you&#8217;re not just limited to fetching URL&#8217;s (using wget) - you can also execute a whole load of other programs - providing you know the right commands (or parameters, or both)!</p>
<p>The best thing about this Windows Cron method is you don&#8217;t need to have access to your web server for it to work - just any PC that is connected to the Internet (note: it needs to be connected when the Cron is scheduled to &#8220;fire&#8221;!). It&#8217;s also free and, because it runs as standard in Windows, it doesn&#8217;t use up any additional memory resources, which is one of the reasons <a href="http://www.mackney.com/">birf</a> loves it.</p>
<p>I hope this has helped you out.</p>
<p>The alternative of course is to use Linux&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamescrooke.co.uk/blog/10/cron-for-windows-iis/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASP character trim function</title>
		<link>http://www.jamescrooke.co.uk/blog/8/asp-character-trim-function/</link>
		<comments>http://www.jamescrooke.co.uk/blog/8/asp-character-trim-function/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 12:03:08 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[asp]]></category>

		<category><![CDATA[ctrim]]></category>

		<category><![CDATA[trim]]></category>

		<guid isPermaLink="false">http://www.jamescrooke.co.uk/?p=8</guid>
		<description><![CDATA[I was working on an ASP script that required a trim function similar to the PHP function trim($string, $charset);. In PHP, you can start with the word "@apples@" and do print trim($word, "@"); to get "apples" (<a href="http://www.php.net/trim">www.php.net/trim</a>).

In ASP, the trim function doesn't allow an optional character parameter, so I wrote a character function of my own called "ctrim" that does it...
]]></description>
			<content:encoded><![CDATA[<p>Happy New Year!</p>
<p>First post of the year, but a quick one.</p>
<p>I was working on an ASP script that required a trim function similar to the PHP</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">function trim($string, $charset);</div></td></tr></tbody></table></div>
<p>. In PHP, you can start with the word &#8220;@apples@&#8221; and do</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">print trim($word, &quot;@&quot;);</div></td></tr></tbody></table></div>
<p>to get &#8220;apples&#8221; (<a href="http://www.php.net/trim">www.php.net/trim</a>).</p>
<p>In ASP, the trim function doesn&#8217;t allow an optional character parameter, so I wrote a character function of my own called &#8220;ctrim&#8221; that does it;</p>
<div class="codecolorer-container asp " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="asp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">function</span> ctrim<span class="br0">&#40;</span>text, char<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="kw3">trim</span><span class="br0">&#40;</span>char<span class="br0">&#41;</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ctrim <span class="sy0">=</span> <span class="kw3">trim</span><span class="br0">&#40;</span>text<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; text <span class="sy0">=</span> <span class="kw3">trim</span><span class="br0">&#40;</span>text<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> left<span class="br0">&#40;</span>text, <span class="kw3">len</span><span class="br0">&#40;</span>char<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">=</span> char <span class="kw1">then</span> text <span class="sy0">=</span> mid<span class="br0">&#40;</span>text, <span class="kw3">len</span><span class="br0">&#40;</span>char<span class="br0">&#41;</span>+<span class="nu0">1</span>, <span class="kw3">len</span><span class="br0">&#40;</span>text<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">end</span> <span class="kw1">if</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> right<span class="br0">&#40;</span>text, <span class="kw3">len</span><span class="br0">&#40;</span>char<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">=</span> char <span class="kw1">then</span> text <span class="sy0">=</span> mid<span class="br0">&#40;</span>text, <span class="nu0">1</span>, <span class="kw3">len</span><span class="br0">&#40;</span>text<span class="br0">&#41;</span>-<span class="kw3">len</span><span class="br0">&#40;</span>char<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">end</span> <span class="kw1">if</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ctrim <span class="sy0">=</span> text<br />
&nbsp; &nbsp; <span class="kw1">end</span> <span class="kw1">if</span><br />
<span class="kw1">end</span> <span class="kw2">function</span></div></td></tr></tbody></table></div>
<p>To use it, just use;</p>
<div class="codecolorer-container asp " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="asp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">response</span>.<span class="kw3">write</span><span class="br0">&#40;</span>ctrim<span class="br0">&#40;</span><span class="st0">&quot;@apples@&quot;</span>, <span class="st0">&quot;@&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.jamescrooke.co.uk/blog/8/asp-character-trim-function/feed/</wfw:commentRss>
		</item>
		<item>
		<title>UK Domain Name Expiry</title>
		<link>http://www.jamescrooke.co.uk/blog/5/uk-domain-name-expiry/</link>
		<comments>http://www.jamescrooke.co.uk/blog/5/uk-domain-name-expiry/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 08:49:30 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[Random]]></category>

		<category><![CDATA[nominet]]></category>

		<category><![CDATA[uk domain expiry]]></category>

		<guid isPermaLink="false">http://www.jamescrooke.co.uk/?p=5</guid>
		<description><![CDATA[I was pleased today as two domains that I have been watching for 99 days exactly, finally became available to register again;
http://www.web-diagnostics.co.uk (and the same domain, just without the hyphen).
Suspended UK Domain Names naturally become available to the public 92 or 99 days from their renewal date.
I have no idea why it is 92 or [...]]]></description>
			<content:encoded><![CDATA[<p>I was pleased today as two domains that I have been watching for 99 days exactly, finally became available to register again;</p>
<p><a href="http://www.web-diagnostics.co.uk/">http://www.web-diagnostics.co.uk</a> (and the same domain, just without the hyphen).</p>
<p>Suspended UK Domain Names naturally become available to the public <strong><span style="font-size:130%;">92</span></strong> or <strong><span style="font-size:130%;">99</span></strong> days from their renewal date.</p>
<p>I have no idea why it is 92 or 99 - but it just is and the two I managed to get today are the fifth and sixth I have managed to &#8220;steal&#8221; in my time, which includes; www.cj-design.co.uk and www.live-support.co.uk.</p>
<p>My tips for ensuring you snag your domain are;</p>
<ol>
<li>Check the Nominet WHOIS database at www.nic.uk directly.</li>
<li>Check before and after the hour passes, usually it will become available in the morning (mine was at 8am)</li>
<li>Once you see those magical words &#8220;This domain name has not been registered&#8221; register it quickly with a registrar that you can rely on (ideally one you&#8217;ve already got an account with).</li>
</ol>
<p>If you can&#8217;t be bothered to do the above then you could sign up for a domain-dropping service who pretty much does the same as the above, except they automate the process - which for me, can lead to problems. It&#8217;s always better to do it manually if you can.</p>
<p>I have big plans for my &#8220;Web Diagnostics&#8221; application, which I plan to launch as a free service in 2009, weather permitting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamescrooke.co.uk/blog/5/uk-domain-name-expiry/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MySQL Bubble Results Trick</title>
		<link>http://www.jamescrooke.co.uk/blog/3/mysql-bubble-results-trick/</link>
		<comments>http://www.jamescrooke.co.uk/blog/3/mysql-bubble-results-trick/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 12:25:46 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[Databases]]></category>

		<category><![CDATA[mysql snippets]]></category>

		<guid isPermaLink="false">http://www.jamescrooke.co.uk/?p=3</guid>
		<description><![CDATA[I have discovered a cool MySQL trick that allows you to order a result set by a specified list - before ordering it by column X, Y or Z etc.]]></description>
			<content:encoded><![CDATA[<p>I have discovered a cool MySQL trick that allows you to order a result set by a specified list - before ordering it by column X, Y or Z etc.</p>
<p>Here&#8217;s an example&#8230;.</p>
<p>If I had a table called &#8220;user&#8221; with the following contents;</p>
<table border="1" cellspacing="0" cellpadding="3">
<tbody>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>1</td>
<td>James</td>
<td>24</td>
</tr>
<tr>
<td>2</td>
<td>Matthew</td>
<td>26</td>
</tr>
<tr>
<td>3</td>
<td>Richard</td>
<td>30</td>
</tr>
<tr>
<td>4</td>
<td>Colin</td>
<td>30</td>
</tr>
</tbody>
</table>
<p>And I did;</p>
<div class="codecolorer-container mysql " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="mysql codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">SELECT</span> name <span class="kw1">FROM</span> <span class="kw23">user</span> <span class="kw1">ORDER BY</span> name <span class="kw1">ASC</span></div></td></tr></tbody></table></div>
<p>I would get;</p>
<p>Colin<br />
James<br />
Matthew<br />
Richard</p>
<p>If I wanted &#8220;Richard&#8221; to appear first, I could do;</p>
<div class="codecolorer-container mysql " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="mysql codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">SELECT</span> name <span class="kw1">FROM</span> <span class="kw23">user</span> <span class="kw1">ORDER BY</span><span class="sy2">,</span> <span class="kw13">FIND_IN_SET</span><span class="br0">&#40;</span>id<span class="sy2">,</span> <span class="nu0">3</span><span class="br0">&#41;</span> <span class="kw1">DESC</span><span class="sy2">,</span> name <span class="kw1">ASC</span></div></td></tr></tbody></table></div>
<p>Or even;</p>
<div class="codecolorer-container mysql " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="mysql codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">SELECT</span> <span class="sy1">*</span> <span class="kw1">FROM</span> <span class="kw23">user</span> <span class="kw1">ORDER BY</span><span class="sy2">,</span> <span class="kw13">FIND_IN_SET</span><span class="br0">&#40;</span>name<span class="sy2">,</span> <span class="st0">&quot;Richard&quot;</span><span class="br0">&#41;</span> <span class="kw1">DESC</span><span class="sy2">,</span> name <span class="kw1">ASC</span></div></td></tr></tbody></table></div>
<p>The magic happens using the <strong>&#8220;FIND_IN_SET&#8221;</strong> function (details here; <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set">http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set</a>).</p>
<p>FIND_IN_SET(str, strlist) is a String function that returns a value in the range of 1 to N if the string str is in the string list strlist consisting of N substrings. A string list is a string composed of substrings separated by &#8220;,&#8221; characters.</p>
<p>A more practical example would be if you had a table of classified adverts and wanted to show those that belong to a certain category first, e.g.;</p>
<div class="codecolorer-container mysql " style="overflow:auto;white-space:nowrap;width:550px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="mysql codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">SELECT</span> <span class="sy1">*</span> <span class="kw1">FROM</span> classified <span class="kw1">ORDER BY</span><span class="sy2">,</span> <span class="kw13">FIND_IN_SET</span><span class="br0">&#40;</span>categoryId<span class="sy2">,</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="kw1">DESC</span><span class="sy2">,</span> dateAdded <span class="kw1">DESC</span></div></td></tr></tbody></table></div>
<p>This would show the classified ads in order of date (dateAdded) but with those from categoryId &#8220;1&#8243; first.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamescrooke.co.uk/blog/3/mysql-bubble-results-trick/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
