<?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>The Journal of Tim Roberts &#187; Web Development</title>
	<atom:link href="http://www.wiseguysonly.com/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wiseguysonly.com</link>
	<description>PHP,MySQL and jQuery Developer</description>
	<lastBuildDate>Sun, 20 Jun 2010 17:12:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Select and Unselect All Checkboxes with jQuery</title>
		<link>http://www.wiseguysonly.com/2010/01/15/select-and-unselect-all-checkboxes-with-jquery/</link>
		<comments>http://www.wiseguysonly.com/2010/01/15/select-and-unselect-all-checkboxes-with-jquery/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 19:01:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.wiseguysonly.com/?p=308</guid>
		<description><![CDATA[I&#8217;ve been working with jQuery to spice up my interfaces for over 12 months now and figured it&#8217;s time to share some of the little techniques I&#8217;ve developed on the way.
The first is something I use quite alot when I am giving users the ability to administer lists of items in bulk. That including a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with jQuery to spice up my interfaces for over 12 months now and figured it&#8217;s time to share some of the little techniques I&#8217;ve developed on the way.</p>
<p>The first is something I use quite alot when I am giving users the ability to administer lists of items in bulk. That including a checkbox that when checked sets the state of all the checkboxes beside a list of items to &#8220;checked&#8221;. Naturally unchecking it will uncheck all checkboxes. I&#8217;m sure you get the picture here&#8217;s the code based on two scenarios depending on your preference. But firstly you need to include the jQuery library in the head of your document (I grab mine straight from Google&#8217;s repository to save my bandwidth):</p>
<p><span id="more-308"></span></p>
<p><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;</code></p>
<p>and then somewhere in your document a controller checkbox that toggles all the others (note the call to toggleChecked when the state of the checkbox changes):</p>
<p><code>&lt;input type="checkbox" onclick="toggleChecked(this.checked)"&gt; Select / Deselect All</code></p>
<p>Now here are  two versions of the toggleChecked function dependent on the semantics of your document. The only real difference is the jQuery selector for your list checkboxes:</p>
<p><strong>1: All checkboxes have a class of  &#8220;checkbox&#8221; (&lt;input type=&#8221;checkbox&#8221; class=&#8221;checkbox&#8221; /&gt;)</strong><br />
<code>function toggleChecked(status) {<br />
$(".checkbox").each( function() {<br />
$(this).attr("checked",status);<br />
})<br />
}</code></p>
<p><strong>2: All the checkboxes are contained within a div with an arbitary id:</strong></p>
<p><code>&lt;div id="checkboxes"&gt;<br />
&lt;input type="checkbox" /&gt;<br />
&lt;input type="checkbox" /&gt;<br />
&lt;input type="checkbox" /&gt;<br />
&lt;/div&gt;</code></p>
<p>In this case the function would look like this:</p>
<p><code>function toggleChecked(status) {<br />
$("#checkboxes input").each( function() {<br />
$(this).attr("checked",status);<br />
})<br />
</code></p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2010/01/15/select-and-unselect-all-checkboxes-with-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A workaround for the CakePHP alphaNumeric issue</title>
		<link>http://www.wiseguysonly.com/2009/11/27/a-workaround-for-the-cakephp-alphanumeric-issue/</link>
		<comments>http://www.wiseguysonly.com/2009/11/27/a-workaround-for-the-cakephp-alphanumeric-issue/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 14:50:51 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.wiseguysonly.com/?p=278</guid>
		<description><![CDATA[Recently whilst building a CakePHP app on a shiny new server I noticed some unexpected behaviour when using an alphaNumeric rule to validate a model. Whatever I passed into the model returned false. That is to say that even a valid alphanumeric string threw up an exception. (if you haven&#8217;t already dived into CakePHP, you [...]]]></description>
			<content:encoded><![CDATA[<p>Recently whilst building a CakePHP app on a shiny new server I noticed some unexpected behaviour when using an alphaNumeric rule to validate a model. Whatever I passed into the model returned false. That is to say that even a valid alphanumeric string threw up an exception. (if you haven&#8217;t already dived into <a href="http://www.cakephp.org">CakePHP</a>, you should &#8211; it&#8217;s a rapid development framework based on <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" title="Model View Controller">MVC</a>.)</p>
<p>The issue seems to be tied to PHP 5.1.2 and the way regular expressions are handled, however it seems the it may appear in other configurations too. Before I get to a workaround, note I haven&#8217;t levelled the &#8220;bug&#8221; word at either PHP nor CakePHP &#8211; for all I know it could be a difference of opinion on how something should be handled. What I do know is that I would rather harness CakePHP&#8217;s flexibility to create custom model rules than try upgrading my current live server PHP installation.</p>
<p>Here is an example of how you should be able to implement the alphaNumeric rule using validation in CakePHP based on a simpliefied model called &#8220;User&#8221;:<br />
class User extends AppModel</p>
<p>{<br />
<code>var $name = 'User';<br />
var $helpers = array('Form');<br />
var $validate = array(<br />
'username' =&gt; array(<br />
'loginRule-1' =&gt; array(<br />
<em> <strong>'rule' =&gt; 'alphaNumeric',</strong></em><br />
'last' =&gt; true,<br />
'message' =&gt; 'Only letters and numbers allowed'<br />
));<br />
}</code></p>
<p>The rule in bold italics above is the one that doesn&#8217;t always work. However this can be easily rectified with a custom rule built on a regular expression seeking out valid alphanumeric strings.</p>
<p>To achieve this the alphaNumeric rule just needs to be replaced with this:</p>
<p><code><strong><em>"rule" => array('custom', '/^[a-z0-9]*$/i'),</strong></em></code></p>
<p>Problem solved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2009/11/27/a-workaround-for-the-cakephp-alphanumeric-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Launch Sports Recruitment International</title>
		<link>http://www.wiseguysonly.com/2009/04/08/new-launch-sports-recruitment-international/</link>
		<comments>http://www.wiseguysonly.com/2009/04/08/new-launch-sports-recruitment-international/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 13:47:29 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Web Design in Spain]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.wiseguysonly.com/?p=242</guid>
		<description><![CDATA[The latest project of my fledgling web design company in Spain, Zumo Internet has left the shelves. Sports Recruitment International is a re-tool of an already successful web site for a major recruiter of professionals in the sports and leisure industry.
We built the site in co-operation with T-MAX media from Oxford. Our input was cutting [...]]]></description>
			<content:encoded><![CDATA[<p>The latest project of my fledgling <a href="http://www.zumointernet.com">web design company in Spain</a>, Zumo Internet has left the shelves. <a href="http://www.sportsrecruitment.com">Sports Recruitment International</a> is a re-tool of an already successful web site for a major recruiter of professionals in the sports and leisure industry.</p>
<p>We built the site in co-operation with T-MAX media from Oxford. Our input was cutting the new designs into valid XHTML and CSS, building some custom jQuery functionality and programming new features into their content management system. The result is a high-impact site for a major corporate client &#8211; and all just as Zumo Internet turns 1.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2009/04/08/new-launch-sports-recruitment-international/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Launch Commercial Roofing and Single Ply Membrane products.</title>
		<link>http://www.wiseguysonly.com/2009/02/26/new-launch-commercial-roofing-and-single-ply-membrane-products/</link>
		<comments>http://www.wiseguysonly.com/2009/02/26/new-launch-commercial-roofing-and-single-ply-membrane-products/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 18:55:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Web Design in Spain]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.wiseguysonly.com/?p=227</guid>
		<description><![CDATA[The most recent project from my web design company in Spain, Zumo Internet has been launched. IPS UK Ltd supply commercial roofing products. They supply and arrange contracting for some of the largest roofing projects in the UK as can be seen from their case studies of installed roofing systems.

They also specialize in commercial and [...]]]></description>
			<content:encoded><![CDATA[<p>The most recent project from my web design company in Spain, <a href="http://www.zumointernet.com">Zumo Internet</a> has been launched. <a href="http://www.ipsukltd.co.uk">IPS UK Ltd supply <strong>commercial roofing products</strong></a>. They supply and arrange contracting for some of the largest roofing projects in the UK as can be seen from their <strong><a href="http://www.ipsukltd.co.uk/case-studies.php">case studies of installed roofing systems</a></strong>.</p>
<p><span id="more-227"></span></p>
<p>They also specialize in commercial and domestic <strong><a href="http://www.ipsukltd.co.uk/green-roofs.php">green roofs</a></strong>.  Green roofs / vegetated roofs or roofs with vegetated spaces &#8211; are a simple, attractive, ecologically beneficial and economically viable solution to many of today&#8217;s environmental issues. They have been adopted extensively in Europe (particularly in Germany) but have not really been taken up to the same extent in this country.</p>
<p>Zumo Internet designed and developed a content managed site for them as well as building intranet so they can manage their <strong>commercial roofing projects</strong> and keep a track on clients and warranties for roofing systems provided by them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2009/02/26/new-launch-commercial-roofing-and-single-ply-membrane-products/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thickbox, accessibility and search engine optimisation.</title>
		<link>http://www.wiseguysonly.com/2009/02/22/thickbox-accessibility-and-search-engine-optimisation/</link>
		<comments>http://www.wiseguysonly.com/2009/02/22/thickbox-accessibility-and-search-engine-optimisation/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 10:21:09 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.wiseguysonly.com/?p=205</guid>
		<description><![CDATA[Recently I noticed that whilst my new project the Vietnam War Timeline was organically racing up the search engines, through virtue of being in a niche and growing daily in content, the bounce rate was exceptionally high. A lot of traffic was coming in but not venturing beyond the entry page.
After a very quick investigation [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I noticed that whilst my new project the <a href="http://www.vietnam-timeline.com">Vietnam War Timeline</a> was organically racing up the search engines, through virtue of being in a niche and growing daily in content, the bounce rate was exceptionally high. A lot of traffic was coming in but not venturing beyond the entry page.</p>
<p>After a very quick investigation it became apparent why this was: all links off the timeline fire a new <a href="http://jquery.com/demo/thickbox/">Thickbox</a> window with the relevant content. It&#8217;s a nice way to keep people within the timeline when they need to look at more content. Moreover, it&#8217;s unobtrusive, meaning the links can just be followed as normal by non-javascript enabled browsers.<span id="more-205"></span></p>
<p>However, therein lies the issue of the exceptional bounce rate.</p>
<p>The Thickbox pages are all indexed well by the search engines. Indeed, as they often hold the relevant content, they figure higher than the home page itself for many searches. But these individual pages are devoid of navigation and are singletons in the sense that they give no indication of more related information being available.  In SEO terms they are <em>orphaned pages</em> and in real user terms they offer no way for the user to investigate more of the site.</p>
<p>You&#8217;re probably ahead of me with a solution here; it&#8217;s a pretty simple one:</p>
<ol>
<li>include navigation in all content;</li>
<li>if the content is opened by Thickbox, destroy the navigation.</li>
</ol>
<p>In the iframed page the following Javascript achieves this:</p>
<p>&lt;script&gt;<br />
if(typeof parent.tb_remove == &#8216;function&#8217;) {<br />
document.getElementById(&#8221;nav&#8221;).style.display=&#8221;none&#8221;;<br />
}<br />
&lt;/script&gt;</p>
<p>This conditional statement checks the parent window for a function called tb_remove (the function that closes thickbox). If this evaluates to true we can use any dom selectors we like to hide page elements we don&#8217;t want to show. If the iframed page is accessed directly either by a real user or a search engine, the navigation will not be destroyed and the page will no longer be orphaned.</p>
<p>See it in action by accessing the first item from the <a href="http://www.vietnam-timeline.com">Vietnam War Timeline &#8211; May 7th &#8211; French defeated at the battle of Dien Bien Phu</a> and then <a href="http://www.vietnam-timeline.com/vietnam-war-event_18_french-defeated-at-the-battle-of-dien-bien-phu?KeepThis=true&amp;TB_iframe=true&amp;height=400&amp;width=600">try accessing the same page directly</a>.</p>
<p>A small price to pay for added SEO and usability in Thickbox.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2009/02/22/thickbox-accessibility-and-search-engine-optimisation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tips for Manipulating dates in MySQL.</title>
		<link>http://www.wiseguysonly.com/2009/02/06/tips-for-manipulating-dates-in-mysql/</link>
		<comments>http://www.wiseguysonly.com/2009/02/06/tips-for-manipulating-dates-in-mysql/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 19:52:07 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.wiseguysonly.com/?p=197</guid>
		<description><![CDATA[Bypassing PHP to manipulate dates.
I despise working with dates in PHP. So much so that I now manipulate my dates using MySQL so I have everything I want in a php variable delivered by one SQL statement. Adding, subtracting, calculating differences and performing other date manipulations can be a pain in PHP. If you have [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Bypassing PHP to manipulate dates.</strong></p>
<p>I despise working with dates in PHP. So much so that I now manipulate my dates using MySQL so I have everything I want in a php variable delivered by one SQL statement. Adding, subtracting, calculating differences and performing other date manipulations can be a pain in PHP. If you have a database connection running in your application it can be much quicker and easier to read if you work with dates in your SQL. The key to this is that you <em>don&#8217;t</em> need to work with tables and records in a database to use SQL. Many of the examples below don&#8217;t make queries against any record sets and yet they return valid results.<span id="more-197"></span></p>
<p><strong>Adding or subtracting time from dates in MySQL.</strong></p>
<p>Often when I work with PayPal subscriptions I have to update a users renewal date on my database by say 6 months etc. MySQL has a very simple way of dealing with this in the INTERVAL statement. For example to add 1 month to todays date you can do this:</p>
<p>SELECT NOW() + INTERVAL 1 MONTH</p>
<p>Conversely to subtract 5 days from the current date do the following:</p>
<p>SELECT NOW() &#8211; 5 DAY</p>
<p>Let&#8217;s say you want to add a year to a subscribtion by updating the field renewal_date:</p>
<p>UPDATE users SET renewal date = renewal_date + INTERVAL 1 YEAR</p>
<p>There are good few timescales that can be used with INTERVAL including SECOND, MINUTE, DAY, WEEK, MONTH, YEAR.</p>
<p><strong>Formatting dates in MySQL.</strong></p>
<p>MySQL uses the American date format of YYY-MM-DD. I don&#8217;t care for it any more than I care for using the property &#8220;color&#8221; in CSS, but I can&#8217;t change it. To change the way a date appears in MySQL, the true power-tool is DATE_FORMAT. This takes 2 arguments: the date you want to format and the new appearance of this date.</p>
<p>For instance:</p>
<p>SELECT DATE_FORMAT(NOW(),&#8217;%d/%m/%Y&#8217;) as display_date</p>
<p>Would return something like:</p>
<p>display_date=&gt;27/03/2007</p>
<p>Of  course, in this instance PHP&#8217;s date() function would be just as easy to use, but when you are dealing with a date from a field DATE_FORMAT is irreplaceable.</p>
<p><a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format">A full list of date formatting codes is avaliable in the MySQL Reference Manual</a>.</p>
<p><strong>Calculating the difference between two dates in MySQL</strong></p>
<p>Another simple task when you use the DATEDIFF function. The first argument is the start date, and the second is the date you want to calcuate the difference to or from:</p>
<p>SELECT DATEDIFF(&#8221;2007-12-31&#8243;,&#8221;2007-12-30&#8243;)</p>
<p>Gives us a value of 1.</p>
<p>SELECT DATEDIFF(&#8221;2007-12-28&#8243;,&#8221;2007-12-31&#8243;)</p>
<p>Give us a value of -3</p>
<p>The results of DATEDIFF are given in days.</p>
<p><strong>Selecting parts of a date in MySQL.</strong></p>
<p>You may want to return a part of a date such as the day that a specific date falls on, or the hour that a task is due on a certain day. There are a number of functions to get specific parts of a date. All you have to do is feed them with a date:</p>
<p>SELECT DAYNAME(&#8221;2004-02-13&#8243;)</p>
<p>Would return &#8220;Friday&#8221;</p>
<p>Other useful functions for extracting date parts are:</p>
<p>DAY() &#8211; returns the day of the month (e.g 13)<br />
MONTH() &#8211; returns the month name<br />
YEAR() &#8211; returns the year<br />
WEEK() &#8211; returns the week number</p>
<p><strong>Digging Deeper</strong></p>
<p>All the above are very simple techniques that will make your day to day use of dates in your coding more pleasant. However, they are the tip of the iceberg in MySQL date manipulation and should you wish to go further, th<a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html">e MySQL reference manual has a comprehensive section on date functions.</a></p>
<pre class="programlisting"><strong class="userinput"></strong></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2009/02/06/tips-for-manipulating-dates-in-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Drag and drop reordering of database fields (sortables) with jQuery</title>
		<link>http://www.wiseguysonly.com/2008/12/07/drag-and-drop-reordering-of-database-fields-sortables-with-jquery/</link>
		<comments>http://www.wiseguysonly.com/2008/12/07/drag-and-drop-reordering-of-database-fields-sortables-with-jquery/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 18:21:17 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.wiseguysonly.com/?p=143</guid>
		<description><![CDATA[This tutorial explains how to display a list of items from a database that can be reordered in real time by dragging and dropping, using the jQuery library. Moreover, no page reload is required on every reorder. If you want a bigger introduction to why you may want to do this I suggest reading my [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial explains how to display a list of items from a database that can be reordered in real time by dragging and dropping, using the jQuery library. Moreover, no page reload is required on every reorder. If you want a bigger introduction to why you may want to do this I suggest reading my tutorial on <a href="/2006/08/11/drag-and-drop-reordering-of-database-fields-with-ajax/">how to achieve the same functionality using scriptaculous</a>.</p>
<p>Previously I have explained how to achieve this in <a href="/2006/08/11/drag-and-drop-reordering-of-database-fields-with-ajax/">Scriptaculous</a> and <a href="/2007/10/10/drag-and-drop-reordering-of-database-fields-sortables-with-mootools/">Mootools</a>.</p>
<p><span id="more-143"></span></p>
<p><strong>Step one: Include the jQuery libraries.</strong></p>
<p>Grab <a href="http://docs.jquery.com/Downloading_jQuery">jQuery</a> and <a href="http://ui.jquery.com/download_builder/">jQuery UI</a> libraries.</p>
<p>Include them in the head of your document:<br />
<code>&lt;<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text/javascript" </span><span class="attribute-name">src</span>=<span class="attribute-value">"javascripts/jquery-1.2.6.min.js"</span>&gt;&lt;/<span class="end-tag">script</span>&gt;<br />
&lt;<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text/javascript" </span><span class="attribute-name">src</span>=<span class="attribute-value">"javascripts/jquery-ui-personalized-1.5.2.min.js"</span>&gt;&lt;/<span class="end-tag">script</span>&gt;</code></p>
<p><strong>Step two: Build a list of items from the database.</strong></p>
<p>Give your list and id &#8211; I am using item_list for this tutorial &#8211; and then make sure each list item has an id of &#8220;item_PRIMARYKEY&#8221; where PRIMARYKEY is the key of the item from the database. Here is something similar to the list you should have:</p>
<p><code><br />
&lt;ul id="item_list" &gt;<br />
&lt;li id="item_1"&gt;Item One&lt;/li&gt;<br />
&lt;li id="item_2"&gt;Item Two&lt;/li&gt;<br />
&lt;li id="item_3"&gt;Item Three&lt;/li&gt;<br />
&lt;li id="item_4"&gt;Item Four&lt;/li&gt;<br />
&lt;/ul&gt;</code></p>
<p><strong>Step 3: Make the list sortable and add a callback to our database script.</strong></p>
<p>Using jQuery&#8217;s onload function or by adding the following script below our list,  inject some javascript into our list to make the list items sortable</p>
<p><code> $("#item_list").sortable({stop:function(i) {<br />
$.ajax({<br />
type: "GET",<br />
url: "server_items_reorder.php",<br />
data: $("#item_list").sortable("serialize")<br />
});</code></p>
<p>Let&#8217;s look at this line by line so you can understand what is happening.</p>
<p>Line one uses the jQuery selector to target the element with an id of item_list (our unordered list in this case). We then apply the sortable plugin from jQuery UI.</p>
<p><a href="http://docs.jquery.com/UI/Sortable/sortable#options">Sortable has a number of options available</a>, but in this case we are going to use the stop option (when sorting has finished) to make an ajax call. The important options in our ajax call are as follows:</p>
<ul>
<li>type: the type of call (in this case GET);</li>
<li>url: (where the ajax post should be made) in this case &#8220;server_items_reorder.php&#8221;;</li>
<li>data : the string the makes up our GET call;</li>
</ul>
<p>The data can be easily built up by using more of the inbuilt functionality of jQuery&#8217;s sortable:</p>
<p><code>$("#item_list").sortable("serialize")</code></p>
<p>This takes the current order of our list and builds it into an array that can be passed on like a GET string:</p>
<p>item[]=1&amp;item[]=2&amp;item[]=3&amp;item[]=4</p>
<p>jQuery automatically serializes the list item id&#8217;s  into this array so you can see why I chose to give them the id item_PRIMARYKEY for the ease offered by convention.</p>
<p>So now we are making a ajax call and padding on the new list order we can write a script to update the database.</p>
<p><strong>Step four: The database script (updating the position).</strong></p>
<p>I am assuming your database table has an extra field called &#8220;position&#8221; that you can use to hold an integer of each items position as relating to its peers. What we need to do now is create our server_items_reorder.php script to collect the array of items and update the database. Here is that script:</p>
<p><code>// YOUR DB CONNECTION HERE<br />
foreach($_GET['item'] as $key=&gt;$value) {<br />
mysql_query("UPDATE my_items" SET position = '" . $key . "' WHERE id ='" . $value . "'");<br />
}</code></p>
<p>This script is simple enough to be written in the language of your choice. It collects the array of items from the GET variable and for each one updates the position based on the id of the item.</p>
<p>That&#8217;s all there is to it.</p>
<p>This tutorial is pretty low level as I have written most of these concepts including troubleshooting in my  <a href="/2006/08/11/drag-and-drop-reordering-of-database-fields-with-ajax/">Scriptaculous</a> and <a href="/2007/10/10/drag-and-drop-reordering-of-database-fields-sortables-with-mootools/">Mootools</a> versions of these, so if you experience any difficulties look at those tutorials first, read the user comments and/or post any questions here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2008/12/07/drag-and-drop-reordering-of-database-fields-sortables-with-jquery/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>jQuery table effects plugin &#8211; v1.0</title>
		<link>http://www.wiseguysonly.com/2008/10/12/jquery-table-effects-plugin-v10/</link>
		<comments>http://www.wiseguysonly.com/2008/10/12/jquery-table-effects-plugin-v10/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 12:58:38 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://wiseguysonly.com/?p=78</guid>
		<description><![CDATA[See the demo here.
My first outing into producing a jQuery plugin is the limited, but useful “jQuery table effects”.
The current version defines the following features:

Alternating row colours for readability (striping).
onmouseover and onmouseout events for manipulating the background colour of the row.


Requirements:

jQuery 1.25+
jtable-effects: minified (1kb) &#124; source(1kb)

Optional complete package of demo files (19kb).

Implementation:
Include the jQuery library [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wiseguysonly.com/demos/jquery/table-effects-jquery.html"><strong>See the demo here</strong></a>.</p>
<p>My first outing into producing a jQuery plugin is the limited, but useful “jQuery table effects”.</p>
<p>The current version defines the following features:</p>
<ol>
<li>Alternating row colours for readability (striping).</li>
<li>onmouseover and onmouseout events for manipulating the background colour of the row.</li>
</ol>
<p><span id="more-78"></span></p>
<p><strong>Requirements:</strong></p>
<ul>
<li><a href="http://docs.jquery.com/Downloading_jQuery#Download_jQuery">jQuery 1.25+</a></li>
<li>jtable-effects: <a href="../demos/jquery/javascripts/jtable-1.0.min.js">minified (1kb)</a> | <a href="../demos/jquery/javascripts/jtable-1.0.js">source(1kb)<br />
</a></li>
<li><a href="../demos/jquery/table-effects-jquery.zip">Optional complete package of demo files (19kb)</a>.</li>
</ul>
<p><strong>Implementation</strong>:</p>
<p>Include the jQuery library and the jtable-effects plugin in the head of your document:</p>
<p><code>&lt;<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">“text/javascript” </span><span class="attribute-name">src</span>=<span class="attribute-value">“javascripts/jquery-1.2.6.min.js”</span>&gt;&lt;/<span class="end-tag">script</span>&gt;<br />
&lt;<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">“text/javascript” </span><span class="attribute-name">src</span>=<span class="attribute-value">“javascripts/jtable-1.0.min.js”</span>&gt;&lt;/<span class="end-tag">script</span>&gt;</code></p>
<p>Then call the jTable function for each instance of a table you wish to maniuplate &#8211; do this using the onload functionality of jQuery:</p>
<p><code>&lt;<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">“text/javascript”</span>&gt;<br />
$(document).ready(function(){<br />
jTable(”demo-table”,{stripe:’#EED’,over:’#FC0′,out:’#FFF’});<br />
});<br />
&lt;/<span class="end-tag">script</span>&gt;</code></p>
<p id="line1">The first argument is the id of the table body (tbody) to apply the effects to and the second is an array of options available:</p>
<ul>
<li><em>stripe: </em>defines the html colour reference for alternating rows. (hex or rgb).</li>
<li><em>over:</em> defines the html colour reference for mouseover. (hex or rgb).</li>
<li><em>out:</em> defines the html colour reference for mouseout &#8211; this has no effect on the striped rows which return to the value defined by <em>stripe</em>. (hex or rgb).</li>
</ul>
<p>Finally, <a href="http://wiseguysonly.com/demos/jquery/table-effects-jquery.html">a demonstration of jtable effects 1.0</a> can be seen here and<a href="../demos/jquery/table-effects-jquery.zip"> a set of demo files can be downloaded here (19kb)</a>.</p>
<p>Please post comments, support requests, bug reports and feature requests for v1.1 in the comments here</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2008/10/12/jquery-table-effects-plugin-v10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autocompletion with Scriptaculous and Ajax.</title>
		<link>http://www.wiseguysonly.com/2008/03/09/autocompletion-with-scriptaculous-and-ajax/</link>
		<comments>http://www.wiseguysonly.com/2008/03/09/autocompletion-with-scriptaculous-and-ajax/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 19:40:32 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scriptaculous]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://wiseguysonly.com/?p=45</guid>
		<description><![CDATA[Demo here &#124; Download sample files
This tutorial supercedes my previous turtorial on autocompletion by adding further tips and tricks to make your autocompletion a much better experience for your site users The tutorial is structured in the following way:

Introduction: What is autocompletion and why use it?
How it works.
Getting scriptaculous and building the form.
Building the autocomplete [...]]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://wiseguysonly.com/demos/scriptaculous/ajax-autocompletion/autocomplete.php">Demo here</a> | <a href="http://wiseguysonly.com/downloads/autocompletion.zip">Download sample files</a></strong></p>
<p>This tutorial supercedes my previous turtorial on autocompletion by adding further tips and tricks to make your autocompletion a much better experience for your site users The tutorial is structured in the following way:</p>
<ol>
<li>Introduction: What is autocompletion and why use it?</li>
<li>How it works.</li>
<li>Getting scriptaculous and building the form.</li>
<li>Building the autocomplete server.</li>
<li>Passing back an id to our form.</li>
</ol>
<p><span id="more-45"></span></p>
<h4>1. What is autocompletion and why use it?</h4>
<p>I predict that most people will want to skip this section and get straight to the action, so I will keep it brief. Autocompletion is a means of helping your users when filling in forms. The most common application of autocomplete is found in your web browser’s address bar; as you type the bar makes suggestions of URLs based on previous pages visited. In our example we will query a database of musical artists and give our users suggestions as they type in an artist name field.</p>
<h4>2. How it works.</h4>
<p>As a user types in a specific input field on a form, on each key up event, we use JavaScript to call a script in the background using Ajax (XMLHttpRequest) features built into the Scriptaculous library. Our form will pass the currently typed text to this script and the script will return a list of suggestions which will be dynamically placed in our page. The important thing is that our user can select one of these items by mouse-click or key-stroke to populate the form field instantly.</p>
<h4>3. Getting scriptaculous and building the form.</h4>
<p>This implementation of autocomplete requires 3 components:</p>
<ol>
<li>The Scriptculous libraries;</li>
<li>An HTML form with a single field;</li>
<li>An autocomplete server script</li>
</ol>
<p>I use PHP as my language of choice for the autocomplete server script, but I have tried to keep this tutorial abstract enough to allow you to use your language of choice. The server script is the only thing that changes for different server-side scripting languages. Download the latest version of the <a href="http://script.aculo.us/downloads">Scriptaculous JavaScript Libraries</a> and include them in the head of a new HTML document as below. Don’t forget to change the paths to match your directory structure:</p>
<p><code>&lt;script type="text/javascript" src="lib/prototype.js"&gt;&lt;/script&gt;<br />
&lt;script type="text/javascript" src="src/scriptaculous.js"&gt;&lt;/script&gt;</code></p>
<p>Now add a form to your HTML page’s body. In this form we are going to add a field that will take our search term (with both id and name attributes as “searchterm”) and an empty div with an id of “hint”. This empty div acts as a holder for our hints when they are generated. You should have some HTML looking like this:</p>
<p><code>&lt;input type="text" name="searchterm" id="searchterm" /&gt;<br />
&lt;div id="hint"&gt;&lt;/div&gt;</code></p>
<p>All we need now is to initiate a new call to Scriptaculous’ built in Ajax.Autocomplete method below our HTML code for the autocompleter &#8211; like this:</p>
<p><code>&lt;script type="text/javascript"&gt;<br />
new Ajax.Autocompleter(”searchterm”,”hint”,”server.php”);<br />
&lt;/script&gt;</code></p>
<p>The Ajax.Autocompleter takes 3 arguments: The element supplying the search string, the element to show suggestions in and the server script that will generate our suggestions. With that in place we can write the server script.</p>
<h4>4. Building the autocomplete server.</h4>
<p>The following server is written in PHP connecting to a MySQL database but you can your language of choice and even a flat text file or XML file for the suggestion database. My database table, “Artists”, is simple &#8211; it comprises a unique id field and an artist “name”.</p>
<p>As the Autocompleter sends the value of a form field as a POST variable, we can use this in our server script’s query againstthe database. All we need to do is output an unordered list for the autocompleter. Scriptaculous does the leg work of inserting the latest list into our hint box everytime the user makes a keystroke. Here is my server code in PHP</p>
<p><code>&lt;?<br />
// don't forget your database connection here.<br />
echo "&lt;ul&gt;";<br />
$sql = "SELECT * FROM artists WHERE name LIKE '%" . $_POST['searchterm'] . "%'";<br />
$rs = mysql_query($sql);<br />
while($data = mysql_fetch_assoc($rs)) {<br />
echo "&lt;li id=\"" . $data['id'] . "\"&gt;" . $data['name'] . "&lt;/li&gt;";<br />
}<br />
echo "&lt;/ul&gt;";<br />
?&gt;</code></p>
<p>Note that I have given each list item an id that is the same as that of the record. We will use this shortly for a more advanced technique. But for now we have all we need for a basic autocompleter.</p>
<h4>5. Passing back an id to our form</h4>
<p>Once a user has selected an item from the autocompleter, the string is entered into the textfield. Often, for the sake of efficiency and accuracy it is better to deal with the id of the item than the string name when it is passed on to the next page. To do this we can use some extra functionality of Ajax.Autocompleter along with some JavaScript that will pass the id to a hidden field in our form.</p>
<p>The first thing we need to add to our form is a hidden field with an id that we can reference:</p>
<p><code>&lt;input type="hidden" id="artist_id" name="artist_id" /&gt;</code></p>
<p>Now we can use an extra piece of functionality built into Ajax.Autocompleter that allows us to pick up the id that we included in our list item from the server script. This is an extra option on our autocompleter call:</p>
<p><code>new Ajax.Autocompleter(”searchterm”,”hint”,”server.php”, {afterUpdateElement : getSelectedId});</code></p>
<p>We are telling our autocompleter to run a function called getSelectedId when an item is selected. All we need to do now is write this function to get the id and inject it into our hidden field. Insert the function below the</p>
<p><code>function getSelectedId(text, li) {<br />
$('searchterm').value=li.id;<br />
}</code></p>
<p>And that’s all there is to it. Of course you can be as clever as you want with your autocomplete server script. Try using the LIMIT clause in your SQL to make it run faster. Make your queries more advanced to bring back more specific results. And don’t forget the fun you can have with CSS on your hint div and the list of suggestions that it displays. If you have any implementations of autocompletion using this tutorial, please post them in the comments here.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><a href="http://www.ipsukltd.co.uk/green-roofs.php">Single ply membrane</a> Products</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2008/03/09/autocompletion-with-scriptaculous-and-ajax/feed/</wfw:commentRss>
		<slash:comments>71</slash:comments>
		</item>
		<item>
		<title>Alternating table row colours in PHP.</title>
		<link>http://www.wiseguysonly.com/2006/03/09/alternating-table-row-colours-in-php/</link>
		<comments>http://www.wiseguysonly.com/2006/03/09/alternating-table-row-colours-in-php/#comments</comments>
		<pubDate>Thu, 09 Mar 2006 06:20:21 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.wiseguysonly.com/?p=111</guid>
		<description><![CDATA[Recently I have been tinkering with Ruby on Rails and I came across a rather nice method of alternating row colours using only two lines of code and a couple of CSS rules. I have been using this method in my PHP ever since and never looked back. This is a neat trick to alternate [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have been tinkering with <a href="http://www.rubyonrails.com">Ruby on Rails</a> and I came across a rather nice method of alternating row colours using only two lines of code and a couple of CSS rules. I have been using this method in my PHP ever since and never looked back. This is a neat trick to alternate row colors on a table using PHP.</p>
<p><span id="more-111"></span></p>
<h3>Why would you want to do this?</h3>
<p>Alternating the row colors (sensibly) on tables makes them easier to read. Hard coding styles is easy enough, but when you are bringing rows back dynamically, from a database for example, you can never be sure which row will be where.</p>
<p>Lets say we have an array from the database called $data. Before we iterate over this information, we need to set a variable outside of our loop</p>
<p><code>$current_row = 0;</code></p>
<p>Now inside our loop, we need just one line that will alternate our <code>$current_row</code> count between 1 and 0</p>
<p><code>while( $data = mysql_fetch_array($recordset)) {<br />
$current_row = 1 - $current_row;<br />
... (rest of code goes here)<br />
}</code></p>
<p>What this does is sets the <code>$current_row</code> variable to 1 or 0 on each pass. The maths is that 1 &#8211; 0 = 1 and on the next pass 1 &#8211; 1 = 0 ¦ This logic can continue infinitely.</p>
<p>All we need to do now are two things:</p>
<ol>
<li>Set a dynamic class in the opening table row in our loop:</li>
<li>Create a class for our alternate row(s) in our CSS:<code>.row1 { background: #eed; }<br />
.row0 { background: #fff; }</code></li>
</ol>
<p>Two lines of extra php code, one extra class in your CSS, and you&#8217;re done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wiseguysonly.com/2006/03/09/alternating-table-row-colours-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
