<?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>Chris Jean&#039;s Blog &#187; Development</title>
	<atom:link href="http://chrisjean.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisjean.com</link>
	<description>Linux, WordPress, programming, anime, and other stuff</description>
	<lastBuildDate>Mon, 30 Aug 2010 16:30:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MySQL ERROR 1018: Unable to Follow Symlink in Ubuntu</title>
		<link>http://chrisjean.com/2010/05/21/mysql-error-1018-unable-to-follow-symlink-in-ubuntu/</link>
		<comments>http://chrisjean.com/2010/05/21/mysql-error-1018-unable-to-follow-symlink-in-ubuntu/#comments</comments>
		<pubDate>Fri, 21 May 2010 17:40:31 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[symlink]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1764</guid>
		<description><![CDATA[I recently had a issue getting MySQL to read a specific database. Each time I tried to manually query a table in the database, I received the following error message: ERROR 1018 (HY000): Can't read dir of './default/' (errno: 13) I&#8217;ve seen this message before as it means that there is a permissions issue. I [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I recently had a issue getting MySQL to read a specific database. Each time I tried to manually query a table in the database, I received the following error message:</p>
<pre>ERROR 1018 (HY000): Can't read dir of './default/' (errno: 13)</pre>
<p>I&#8217;ve seen this message before as it means that there is a permissions issue. I checked the ownerships and permissions, and everything seemed to be in order.</p>
<p>The only thing special about this database is that I have it symlinked to another partition. This has always worked in the past, so I was stumped.</p>
<p>The problem turned out to be that Ubuntu has <a href="http://en.wikipedia.org/wiki/AppArmor">AppArmor</a>. This software sets up rules that prevent software from gaining access to different areas of the file system. In my case, AppArmor was preventing read and write access to the actual location of my database files.</p>
<p>The solution was quite easy: First, I added the path that I wanted MySQL to have access to in the AppArmor configuration file for MySQL. Second, I restarted the apparmor service. Here&#8217;s the technical details:</p>
<ol>
<li>On my system, the configuration file that controls MySQL permissions through AppArmor are located at /etc/apparmor.d/usr.sbin.mysqld. The following shows the contents of the file as it now exists:
<pre># vim:syntax=apparmor
# Last Modified: Tue Jun 19 17:37:30 2007
#include 

/usr/sbin/mysqld {
  #include
  #include
  #include
  #include
  #include 

  capability dac_override,
  capability sys_resource,
  capability setgid,
  capability setuid,

  network tcp,

  /etc/hosts.allow r,
  /etc/hosts.deny r,

  /etc/mysql/*.pem r,
  /etc/mysql/conf.d/ r,
  /etc/mysql/conf.d/* r,
  /etc/mysql/my.cnf r,
  /usr/sbin/mysqld mr,
  /usr/share/mysql/** r,
  /var/log/mysql.log rw,
  /var/log/mysql.err rw,
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,
  /var/log/mysql/ r,
  /var/log/mysql/* rw,
  /var/run/mysqld/mysqld.pid w,
  /var/run/mysqld/mysqld.sock w,
  <strong>/home/sites/default/mysql/ rw,
  /home/sites/default/mysql/* rw,</strong>

  /sys/devices/system/cpu/ r,
}</pre>
<p>The two lines in bold show what I added to the configuation. The first line gives read and write access to the directory itself while the second gives read and write access to the files contained in the directory.</li>
<li>After saving the configuration changes, I simply needed to restart the AppArmor daemon. I did this with the following command:
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@rommie</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo service apparmor restart</span>
 * Reloading AppArmor profiles
Skipping profile in /etc/apparmor.d/disable: usr.bin.firefox</pre>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2010/05/21/mysql-error-1018-unable-to-follow-symlink-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Fix width:auto Floated Elements in IE 6</title>
		<link>http://chrisjean.com/2009/09/30/fix-width-auto-floated-elements-in-ie-6/</link>
		<comments>http://chrisjean.com/2009/09/30/fix-width-auto-floated-elements-in-ie-6/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 05:37:53 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[Browser Wars]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Internet Explorer 6]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1604</guid>
		<description><![CDATA[It is popular to use ul and li elements float them and set them to width:auto in CSS in order to create a horizontal list of self-sizing boxes. These can easily be used to create horizontal navigation or a listing of tabs, and it works very well. However, there is one caveat; given the right [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>It is popular to use <code>ul</code> and <code>li</code> elements float them and set them to <code>width:auto</code> in CSS in order to create a horizontal list of self-sizing boxes. These can easily be used to create horizontal navigation or a listing of tabs, and it works very well. However, there is one caveat; given the right mix of CSS this solution doesn&#8217;t work properly in IE 6.</p>
<p>To create this scenario, we can simply use something like the following:</p>
<pre>&lt;style type="text/css"&gt;
    ul {
        height: 30px;
        overflow: hidden;
    }
    ul li {
        float: left;
        width: auto;
    }
    ul li a {
        display: block;
        height: 30px;
    }
&lt;/style&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="#"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#"&gt;Link 2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>This will show the problem in IE 6 nicely. The problem is that IE 6 interprets this mix of CSS and decides that each <code>li</code> element should actually expand out to 100% width.</p>
<p>I&#8217;ll explain how to fix this issue and provide and example page so you can easily play around with the HTML and CSS yourself.</p>

<h3>Fix #1</h3>
<p>A quick way to tame the IE 6 beast is to give the offending element a width of 0. Counter to intuition, this won&#8217;t force the element to an infinitely-small width; rather, it will force IE 6 to automatically-size the width of the element. However, this has an immediate problem, all other browsers will see this width of 0 for what it really is and render nothing for that element since, well, it has a width of 0.</p>
<p>There are a few different ways to correct this:</p>
<ol>
<li>We can use a hack to introduce the width 0 command to IE 6 without having the other browsers take notice. This works and can be implemented by using <code>_width:0</code> to specifically target IE 6. For example:
<pre>#nav ul li {
    width: auto;
    _width: 0;
    float: left;
}</pre>
</li>
<li>Since using a hack isn&#8217;t always preferable, another option is to selectively-load a CSS document that adds the IE 6-only behavior. In the HTML document, you first load the standard stylesheet followed by the IE 6-specific stylesheet:
<pre>&lt;link rel="stylesheet" href="/css/style.css" type="text/css" media="screen" /&gt;
&lt;!--[if lt IE 7]&gt;
    &lt;link rel="stylesheet" href="/css/lt-ie7.css" type="text/css" media="screen" /&gt;
&lt;![endif]--&gt;</pre>
<p>In the IE 6 stylesheet, add the <code>width:0</code> style:</p>
<pre>#nav ul li {
    width: 0;
}</pre>
</li>
<li>We can use CSS selectors that are ignored by IE 6. This doesn&#8217;t use a hack and also avoids using a separate stylesheet.
<pre>#nav ul li {
    width: 0;
    float: left;
}
#nav ul &gt; li {
    width: auto;
}</pre>
</li>
</ol>
<p>Each of these methods work nicely, however, after some additional testing, a new limitation becomes clear. For some reason, IE 6 now decides that only one word should be permitted in each box. Basically, it seems to word-wrap all additional words, effectively cutting them off. Thus the need for another fix.</p>
<h3>Fix #2</h3>
<p>The solution to preventing IE 6 from truncating each element is simple: prevent word wrapping. This is easily done using the <code>white-space:nowrap</code> CSS instruction.</p>
<p>Using the third example above, we can change it to the following to apply this next fix:</p>
<pre>#nav ul li {
    width: 0;
    float: left;
    white-space: nowrap;
}
#nav ul &gt; li {
    width: auto;
}</pre>
<h3>Example Page</h3>
<p>I built an <a href="http://www.gaarai.com/ie6-auto-width-float-fix.html" target="_blank">example page</a> that shows what is actually occurring during each step of this process and shows how each fix improves the rendering in IE 6. The final example renders as it should.</p>
<p>Here is a screenshot that shows how it renders in IE 6:</p>
<div id="attachment_1611" class="wp-caption alignnone" style="width: 525px"><a href="http://www.gaarai.com/ie6-auto-width-float-fix.html" target="_blank"><img class="size-full wp-image-1611 " title="ie-6-nav-issue" src="http://chrisjean.com/wp-content/uploads/2009/09/ie-6-nav-issue.png" alt="ie-6-nav-issue" width="515" height="541" /></a><p class="wp-caption-text">Example Rendering in IE 6</p></div>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/09/30/fix-width-auto-floated-elements-in-ie-6/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Vertically Centering HTML Content via CSS</title>
		<link>http://chrisjean.com/2009/09/27/vertically-centering-html-content-via-css/</link>
		<comments>http://chrisjean.com/2009/09/27/vertically-centering-html-content-via-css/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 05:00:13 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[Browser Wars]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1586</guid>
		<description><![CDATA[Today I  have yet another entry on HTML and CSS. Today it is how to vertically center content in HTML using CSS. You&#8217;d think that there would be a standard definition of how to vertically center any content by now, but there isn&#8217;t. There are a variety of methods out there that do this. I [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Today I  have yet another entry on HTML and CSS. Today it is how to vertically center content in HTML using CSS.</p>
<p>You&#8217;d think that there would be a standard definition of how to vertically center any content by now, but there isn&#8217;t. There are a variety of methods out there that do this. I frequently see people using the line-height CSS property to vertically center content. While this appears to work, it isn&#8217;t very flexible, only works properly if there is only one line of text, and doesn&#8217;t work in all situations.</p>
<p>I found <a href="http://www.jakpsatweb.cz/css/css-vertical-center-solution.html" target="_blank">Yuhu&#8217;s Definitive Solution with Unknown Height</a> which looks great, works properly with all major browsers, doesn&#8217;t have the limitations I&#8217;ve seen in other solutions, and is quite simple to implement. Basically all you have to do is have three divs wrapped around the content you wish to vertically center and use specific styling for those divs.</p>
<p>The following code is what does the magic. Replace the comment with the content to be vertically centered, change the height to match the vertical height of the container, and you&#8217;re set.</p>
<pre>&lt;div style="display:table; height:400px; #position:relative;"&gt;
    &lt;div style="#position:absolute; #top:50%; display:table-cell;
vertical-align:middle;"&gt;
        &lt;div style="#position:relative; #top:-50%"&gt;
            &lt;!-- content to be centered --&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;</pre>
<p>I built a quick <a href="http://chrisjean.com/center_vertically.html" target="_blank">example document</a> that shows how I applied the rules via a style block in the head to keep the HTML clean.</p>
<p>As with my <a href="http://chrisjean.com/2009/09/24/taming-html-lists-across-all-browsers/" target="_blank">taming HTML lists fix</a>, I tested this successfully on the following browsers:</p>
<ul>
<li> OS X
<ul>
<li>Firefox 3.5</li>
<li>Safari 4</li>
</ul>
</li>
<li> Ubuntu (Linux)
<ul>
<li>Firefox 3.5</li>
<li>Google Chrome 4</li>
<li>Konqueror 4.2</li>
<li>Midori 0.1.2</li>
<li>Opera 10</li>
</ul>
</li>
<li> Windows
<ul>
<li>Firefox 3.5</li>
<li>Google Chrome 4</li>
<li>Internet Explorer 6, 7, and 8</li>
<li>Safari 4</li>
</ul>
</li>
</ul>
<p>Thank you Yuhu for the great solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/09/27/vertically-centering-html-content-via-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>man Pages for C Development in Ubuntu</title>
		<link>http://chrisjean.com/2009/09/26/man-pages-for-c-development-in-ubuntu/</link>
		<comments>http://chrisjean.com/2009/09/26/man-pages-for-c-development-in-ubuntu/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 05:00:23 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Mastering The Command Line]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1493</guid>
		<description><![CDATA[I recently tutored a friend in C coding. Since I hadn&#8217;t worked with C in at least 8 years, I really needed to have some references to rely on for syntax and other specifics. Fortunately, there are some easy man pages that can be installed in Ubuntu that offer helpful information that I was able [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I recently tutored a friend in C coding. Since I hadn&#8217;t worked with C in at least 8 years, I really needed to have some references to rely on for syntax and other specifics. Fortunately, there are some easy man pages that can be installed in Ubuntu that offer helpful information that I was able to use to help refresh my memory.</p>
<p>These man pages are easily installed by installing the <code>manpages-dev</code> package. You can install this package via Synaptic or directly on the command line. I like the command line method personally, so I ran <code>sudo apt-get install manpages-dev</code> from the command line to quickly install the package.</p>
<p>After installing the package, I&#8217;m able to access man pages for functions such as <code>printf</code>, <code>opendir</code>, and <code>putc</code>. For each function, it shows the valid syntax as well as what library is required to make use of the function.</p>
<p>The information isn&#8217;t limited to functions as you can also access information on the libraries, such as <code>stdio</code> or <code>string</code>.</p>
<p>To access any of this information, simply run <code>man [function or library name]</code> such as <code>man stdio</code>.</p>
<p>This package isn&#8217;t limited to C functions/libraries. It is a general use Linux development suite of man pages. For a full list of what is installed, check out the <a href="http://packages.ubuntu.com/hardy/all/manpages-dev/filelist" target="_blank">file list</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/09/26/man-pages-for-c-development-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pushing a Webpage Footer to the Bottom of an HTML Page with CSS</title>
		<link>http://chrisjean.com/2009/09/25/pushing-a-webpage-footer-to-the-bottom-of-an-page-with-css/</link>
		<comments>http://chrisjean.com/2009/09/25/pushing-a-webpage-footer-to-the-bottom-of-an-page-with-css/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 05:00:51 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[Browser Wars]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1565</guid>
		<description><![CDATA[Anyone that works with HTML and CSS will tell you that positioning things exactly where you want them to be is often times difficult. If you want to position something somewhere vertically, it becomes even worse. I just finished working on a theme where I needed to force the footer of the layout to the [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Anyone that works with HTML and CSS will tell you that positioning things exactly where you want them to be is often times difficult. If you want to position something somewhere vertically, it becomes even worse.</p>
<p>I just finished working on a theme where I needed to force the footer of the layout to the very bottom of the page. While logically putting the footer after all the other content is easy, making it sit at the very bottom of the page even when the content doesn&#8217;t take up enough space to push it down there is quite difficult.</p>
<p>After struggling with getting this right for a couple of hours, I finally found a site that has done all the hard work for me. <a href="http://www.cssstickyfooter.com/" target="_blank">CSS Sticky Footer</a> is the site that saved my sanity.</p>
<p>CSS Sticky Footer provides a solution that sticks the footer to the bottom of the page in a cross-browser compliant manner. The site reports, and I can confirm, that it works with Internet Explorer 6 through Internet Explorer 8,  Firefox, Google Chrome, Safari, Opera, and Konqueror.</p>
<p>Since the implementation could change, I recommend that you visit the site to get details; however, just in case something happens to the site, I&#8217;m going to add the solution here as well.</p>

<h3>HTML</h3>
<pre>&lt;div id="wrap"&gt;
    &lt;div id="main" class="clearfix"&gt;
        &lt;!-- non-footer content --&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;div id="footer"&gt;
    &lt;!-- footer content --&gt;
&lt;/div&gt;</pre>
<h3>CSS</h3>
<pre>/*
Sticky Footer Solution
by Steve Hatcher

http://stever.ca

http://www.cssstickyfooter.com

*/

* {
    margin: 0;
    padding: 0;
}

/* must declare 0 margins on everything, also for main layout components
use padding, not vertical margins (top and bottom) to add spacing, else
those margins get added to total height and your footer gets pushed down
a bit more, creating vertical scroll bars in the browser */

html, body, #wrap {
    height: 100%;
}

body &gt; #wrap {
    height: auto;
    min-height: 100%;
}

#main {
    padding-bottom: 150px;  /* must be same height as the footer */
}

#footer {
    position: relative;
    margin-top: -150px;  /* negative value of footer height */
    height: 150px;
    clear: both;
} 

/* CLEAR FIX */
.clearfix:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
.clearfix {
    display: inline-block;
}
/* Hides from IE-mac \*/
* html .clearfix {
    height: 1%;
}
.clearfix {
    display: block;
}
/* End hide from IE-mac */</pre>
<h3>Sample</h3>
<p>I have a <a href="http://chrisjean.com/css_sticky_footer.html" target="_blank">sample page</a> available to see this in action.</p>
<p>Many thanks to Steve Hatcher who made my job a lot easier.</p>
<h3>Update</h3>
<p>Someone reported that they have a roughly 45 pixel white gap at the bottom of footer of the sample and that they saw this on Firefox 3.5.3 on Vista. I&#8217;ve tested this on the exact same OS and browser, and I don&#8217;t see it. I&#8217;ve tested this on a huge variety of platforms, browsers, and browser versions, and I can&#8217;t see the gap. Does anyone else see any odd rendering?</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/09/25/pushing-a-webpage-footer-to-the-bottom-of-an-page-with-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Taming HTML Lists Across All Browsers</title>
		<link>http://chrisjean.com/2009/09/24/taming-html-lists-across-all-browsers/</link>
		<comments>http://chrisjean.com/2009/09/24/taming-html-lists-across-all-browsers/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 15:31:39 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[Browser Wars]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1552</guid>
		<description><![CDATA[It seems that every browser rendering engine has a completely different way of rendering lists. I recently had the frustrating job of getting them all to play nicely together. The CSS I ended up using is quite simple and works across all the browsers I tested (list at the bottom). This is the magic bit [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>It seems that every browser rendering engine has a completely different way of rendering lists. I recently had the frustrating job of getting them all to play nicely together.</p>
<p>The CSS I ended up using is quite simple and works across all the browsers I tested (list at the bottom).</p>
<p>This is the magic bit of CSS:</p>
<pre>ul, ol {
    list-style-position: outside;
    margin: 0 0 0 15px;
    padding: 0;
}
ol {
    margin-left: 20px;
    *margin-left: 24px; /* targeted IE 6, 7 fix */
}
li {
    margin: 0;
    padding: 0;
}</pre>
<p>This CSS forces all the browsers to play by the same rules. The end results are nice and clean.</p>
<p>The left margins are necessary to get all the browsers to not clip part of the bullet/number; however, you can change this left margin on ul/ol elements contained within the primary ul/ol if you need to adjust the indentation of each sub-list.</p>
<p>Each browser that I tested rendered the same thing, albeit with slightly different bullets or padding in front of the number.</p>
<p>The following are the browsers I tested:</p>
<ul>
<li>
OS X</p>
<ul>
<li>Firefox 3.5</li>
<li>Safari 4</li>
</ul>
</li>
<li>
Ubuntu (Linux)</p>
<ul>
<li>Firefox 3.5</li>
<li>Google Chrome 4</li>
<li>Konqueror 4.2</li>
<li>Midori 0.1.2</li>
<li>Opera 10</li>
</ul>
</li>
<li>
Windows</p>
<ul>
<li>Firefox 3.5</li>
<li>Google Chrome 4</li>
<li>Internet Explorer 6, 7, and 8</li>
<li>Safari 4</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/09/24/taming-html-lists-across-all-browsers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Recursively Updating Git Submodules</title>
		<link>http://chrisjean.com/2009/09/16/recursively-updating-git-submodules/</link>
		<comments>http://chrisjean.com/2009/09/16/recursively-updating-git-submodules/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 18:30:20 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[submodules]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1528</guid>
		<description><![CDATA[I had fun writing about how I work with Git yesterday. I thought I&#8217;d continue on that thread. I have a solid set of code libraries that I&#8217;ve written that latch into the WordPress themes we produce at iThemes. Each time code is duplicated across different repositories, I break that code out and make it [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I had fun writing about how I work with Git yesterday. I thought I&#8217;d continue on that thread.</p>
<p>I have a solid set of code libraries that I&#8217;ve written that latch into the WordPress themes we produce at <a href="http://ithemes.com/" target="_blank">iThemes</a>. Each time code is duplicated across different repositories, I break that code out and make it into a separate repository. I then link it back into the project as a submodule. This makes it extremely-easy to keep duplicated code across numerous repositories updated with little or no fuss.</p>
<p>After cloning a repository, simply run <code>git submodule init</code> followed by <code>git submodule update</code> in order to initialize all the submodules and update their container folder with the content of the submodule&#8217;s repository. For a long time, this is exactly what I did when I would clone a theme repository to start working on it. However, this quickly wasn&#8217;t enough.</p>
<p>The problem happened as soon as I added a submodule to a repository that was also a submodule of other repositories. Doing the submodule init and update process wouldn&#8217;t do everything I needed in this case as there would be submodules in some subfolder that haven&#8217;t been set up.</p>
<p>I didn&#8217;t want to get into a habit of always switching to other directories and doing the submodule processes there as well since I 1) knew that I would forget all-too-often, thus wasting my time, and 2) knew that this would not be the last time that a submodule had submodules. Heck, there is even the possibility that I&#8217;ll have a submodule that has a submodule that has a submodule. It was immediately clear that I needed a script to do all this dirty work for me. The rest of this post will be about the script I created.</p>

<h3>The Script</h3>
<p>First, I&#8217;ll share the script itself. If you are interested in how it works, continue reading.</p>
<p><a href="http://chrisjean.com/git-submodule-recursive-update" target="_blank">git-submodule-recursive-update</a> (right-click &gt; &#8220;Save Link As&#8230;&#8221; to download)</p>
<p>The script is written in Perl and should work on most systems. I&#8217;ve only tested it on Linux and OS X, so please let me know your results if you try out on Windows.</p>
<pre class="code" style="padding:20px 0 20px;">#!/usr/bin/perl

use strict;
use Cwd;

init_and_update();

exit;

sub init_and_update
{
    my $start_path = cwd();

    my %paths;
    my $updated;

    do
    {
        my $data = `find . -name '.gitmodules'`;
        chomp($data);

        $data =~ s/\/\.gitmodules//g;

        foreach my $path (split(/\n/, $data))
        {
            $paths{$path} = '' if($paths{$path} eq '');
        }

        $updated = 0;

        foreach my $path (sort keys %paths)
        {
            if($paths{$path} eq '')
            {
                chdir($path);
                `git submodule init 2&gt;&amp;1`;
                `git submodule update 2&gt;&amp;1`;
                chdir($start_path);

                if($ARGV[0] eq '--remove-gitmodules')
                {
                    unlink("$path/.gitmodules");
                }

                $paths{$path} = 1;

                $updated++;
            }
        }
    } while($updated);
}</pre>
<h3>The Description</h3>
<p>The functionality should look very straight-forward to anyone that knows Perl.</p>
<ol>
<li>I store the current directory in the <code>$start_path</code> variable in order to always know where home is.</li>
<li>I start a wrapper loop that keeps running until all the possible submodules are initialized and updated.</li>
<li>Using the find command, I look for all the instances of <code>.gitmodules</code> and store the results in <code>$data</code>. The <code>.gitmodules</code> file exists if a repo has submodules.</li>
<li>I remove all the <code>.gitmodules</code> file references from the <code>$data</code> to leave just the paths.</li>
<li>I split the paths into an array and initialize the <code>%paths</code> hash to have a blank value for new paths (stored in the key). Setting this value to blank will flag the following loop that the submodules in that path have not been set up yet.</li>
<li>I create a tracker variable, <code>$updated</code>, to check if anything happened in the loop.</li>
<li>I then loop through the <code>%paths</code> hash to work on each path. If the path&#8217;s hash value is blank, I process that path.</li>
<li>I <code>cd</code> into the repo path, init and update the submodules, and switch back to the starting folder.</li>
<li>If the script is called with the optional <code>--remove-gitmodules</code> argument, I remove the <code>.gitmodules</code> folder while I&#8217;m focused on that folder. I use this for other automation scripts, so it may or may not be of value to you.</li>
<li>I then set the path&#8217;s hash value to <code>1</code> to flag it as done.</li>
<li>Closing out the loop, I update the <code>$updated</code> variable to show that something was updated in this pass.</li>
<li>Finishing up the <code>do</code> loop towards the top, I have <code>while($updated)</code>. Basically, as long as something was updated in the core update loop, I&#8217;ll run everything again. This means that the loop will keep running until it didn&#8217;t find anything else that needed to be updated. When that point is reached, the main loop ends, and the script is finished.</li>
</ol>
<p>I know that there are a number of things I could have done to make for a much more brief, compact script, but I was going to quick production with solid functionality, not brevity. In addition, there are unnecessary elements such as incrementing the <code>$updated</code> variable rather than just setting it to some value. I thought might want to know how many things were updated at some point, so I left it as a counter.</p>
<p>If you found this script helpful, please leave a comment. The more interest these Git-related posts receive, the more motivated I&#8217;ll be to share other processes, developments I&#8217;ve made to make working Git easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/09/16/recursively-updating-git-submodules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating Multiple Git Repositories Easily Using Bash for Loop</title>
		<link>http://chrisjean.com/2009/09/15/updating-multiple-git-repositories-easily-using-bash-for-loop/</link>
		<comments>http://chrisjean.com/2009/09/15/updating-multiple-git-repositories-easily-using-bash-for-loop/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 16:42:14 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[Mastering The Command Line]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1508</guid>
		<description><![CDATA[All of the WordPress themes that I work on for iThemes are managed as Git repositories. Recently, we moved past the 100 repositories mark. That&#8217;s a lot of repositories to manage, and unfortunately, too many of those repositories contain duplicated information. Later on, I might delve into how we use Git to manage our theme [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>All of the <a href="http://wordpress.org/" target="_blank">WordPress</a> themes that I work on for <a href="http://ithemes.com/" target="_blank">iThemes</a> are managed as Git repositories. Recently, we moved past the 100 repositories mark. That&#8217;s a lot of repositories to manage, and unfortunately, too many of those repositories contain duplicated information.</p>
<p>Later on, I might delve into how we use Git to manage our theme repos. For today, however, I&#8217;d like to focus on how I quickly and easily pushed up changes to more than a dozen repos in a single, albeit long, Bash command.</p>
<p>I had finished making updates to 16 <a href="http://ithemes.com/purchase/flexx-theme-wordpress-blog-themes/" target="_blank">Flexx</a> repos, and I needed to push all of those changes up. Since I had multiple working repos in that folder, I was lucky that each of these repos began with the text &#8220;Flexx&#8221;. Also, since they are all part of the same series and need to keep the same version number, that simplified the tagging as all could be tagged as 2.5.0.</p>
<p>Given this information, I simply ran the following command from the directory that contained all the repository directories:</p>
<div class="code">for i in `ls|grep Flexx`; do echo &#8220;&#8212; Pushing $i&#8221;; cd $i; git commit -am &#8217;2.5.0&#8242; &amp;&amp; git push &amp;&amp; git tag 2.5.0 &amp;&amp; git push &#8211;tags; cd ..; echo &#8220;&#8212; Finished $i&#8221;; done</div>
<p>There&#8217;s a lot going on here, so I&#8217;ll break it up and explain what I&#8217;m doing.</p>

<div class="code">for i in `ls|grep Flexx`</div>
<p>This is basically a compound command. Bash&#8217;s <code>for</code> command is being used to step through the results of <code>ls|grep Flexx</code>. Each result will be stored to the variable <code>i</code> which can be referred to with <code>$i</code>.</p>
<p>In other words, I&#8217;m going to loop through each directory that contains the text &#8220;Flexx&#8221; (technically, it isn&#8217;t limited to just directories, but I don&#8217;t have any files containing &#8220;Flexx&#8221;, so I&#8217;m safe). For each iteration of the loop, the variable <code>$i</code> will contain the name of the folder I&#8217;m interested in.</p>
<div class="code">do echo &#8220;&#8212; Pushing $i&#8221;</div>
<p>The most important bit here is <code>do</code>. <code>do</code> simply begins the functional part of the loop and could be followed by any command that I wanted to start the loop with.</p>
<p>The <code>echo</code> command isn&#8217;t technically necessary. I simply have it there so that I can better determine what output belongs to which repository.</p>
<div class="code">cd $i</div>
<p>This is a very important command. It changes the directory to the repository I wish to run commands on.</p>
<div class="code">git commit -am &#8217;2.5.0&#8242; &amp;&amp; git push &amp;&amp; git tag 2.5.0 &amp;&amp; git push &#8211;tags</div>
<p>This is the command that actually does what I want to do in each repo directory. This adds all the modified files, commits them with a message of &#8220;2.5.0&#8243;, pushes the changes to the remote repository, creates a new tag of 2.5.0, and pushes up the new tag.</p>
<p>I have all of these commands chained together with <code>&amp;&amp;</code> so that if one command fails, the other ones won&#8217;t run. This prevents tagging in the event that the repository couldn&#8217;t be committed or pushed.</p>
<div class="code">cd ..</div>
<p>It&#8217;s a small command but necessary. This switches back to the main directory that holds all the repos, thus returning us back to a state that the next loop iteration can work with.</p>
<div class="code">echo &#8220;&#8212; Finished $i&#8221;</div>
<p>As with the other <code>echo</code> command, this simply allows me to keep track of what is going on more easily.</p>
<div class="code">done</div>
<p>The <code>done</code> command finishes out the loop iteration.</p>
<p>I hope that by sharing this you can gain a bit of insight into how I work with repositories while also learning more about how you can do things with Bash.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/09/15/updating-multiple-git-repositories-easily-using-bash-for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git Submodules: Adding, Using, Removing, and Updating</title>
		<link>http://chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/</link>
		<comments>http://chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 05:00:48 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[submodules]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1423</guid>
		<description><![CDATA[I&#8217;ve spent a little more than a month working with Git now. I can honestly say that while there are many things that I like about Git, there are just as many things that I personally find to be a pain in the butt. Submodules specifically have managed to be a thorn in my side [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I&#8217;ve spent a little more than a month working with <a href="http://git-scm.com/" target="_blank">Git</a> now. I can honestly say that while there are many things that I like about Git, there are just as many things that I personally find to be a pain in the butt.</p>
<p>Submodules specifically have managed to be a thorn in my side on many occasions. While the concept of submodules is simple, figuring out how to actually work with them can be a chore. I say &#8220;figuring out&#8221; because not everything about working with submodules is well documented. I&#8217;ll cover two of the more difficult things to figure out: removing and updating submodules from your repository.</p>

<h3>What are Submodules?</h3>
<p>The concept of submodules is brilliant. It essentially allows you to attach an external repository inside another repository at a specific path. In order to illustrate the value of submodules, it will probably be helpful for me to explain how I am using them.</p>
<p>My profession is working with <a href="http://wordpress.org/" target="_blank">WordPress</a> themes. Basically, I develop feature enhancements to the themes. I develop the code for these enhancements in modules that are completely contained in their own folder. This allows for the code to be easily added to other themes and also simplifies code updates/improvements as the code for specific features is consistent across all the themes that use that specific module.</p>
<p>Each theme that we produce is kept in its own Git repository. In addition, I&#8217;ve created a separate repository for each one of these feature modules. Rather than actually putting the feature module code directly into the theme repositories, I simply add the needed feature module repositories as submodules.</p>
<p>For example, we have a theme called FlexxBold. FlexxBold currently includes a total of seven submodules: billboard, contact-page-plugin, featured-images, feedburner-widget, file-utility, flexx-layout-editor, and tutorials. Since I&#8217;m using submodules, the code can be pulled directly from the relevant submodule repositories rather than requiring me to manually update each individual theme repository.</p>
<p>As I mentioned before, not everything in Git is easy to work with. There are four main functions you will need to understand in order to work with Git submodules. In order, you will need to know how to add, make use of, remove, and update submodules. I&#8217;ll cover each of those uses below.</p>
<h3>Adding Submodules to a Git Repository</h3>
<p>Fortunately, adding a submodule to a git repository is actually quite simple. For example, if I&#8217;m in the repository working directory of a new theme called SampleTheme and need to add the billboard repository to the path lib/billboard, I can do so with the following command:</p>
<div class="code">git submodule add git@mygithost:billboard lib/billboard</div>
<p>There are three main parts to this command:</p>
<ul>
<li>git submodule add &#8211; This simply tells Git that we are adding a submodule. This syntax will always remain the same.</li>
<li>git@mygithost:billboard &#8211; This is the external repository that is to be added as a submodule. The exact syntax will vary depending on the setup of the Git repository you are connecting to. You need to ensure that you have the ability to clone the given repository.</li>
<li>lib/billboard &#8211; This is the path where the submodule repository will be added to the main repository.</li>
</ul>
<p>Let&#8217;s check to see how the repository is doing.</p>
<div class="code"><strong>$ git status</strong><br />
# On branch master<br />
# Changes to be committed:<br />
#   (use &#8220;git reset HEAD &lt;file&gt;&#8230;&#8221; to unstage)<br />
#<br />
#       new file:   .gitmodules<br />
#       new file:   lib/billboard<br />
#</div>
<p>Notice how the supplied path was created and added to the changes to be committed. In addition, a new file called .gitmodules was created. This new file contains the details we supplied about the new submodule. Out of curiosity, let&#8217;s check out the contents of that new file:</p>
<div class="code"><strong>$ cat .gitmodules</strong><br />
[submodule "lib/billboard"]<br />
path = lib/billboard<br />
url = git@mygithost:billboard</div>
<p>Being able to modify this file later will come in handy later.</p>
<p>All that is left to do now is to commit the changes and then push the commit to a remote system if necessary.</p>
<h3>Using Submodules</h3>
<p>Having submodules in a repository is great and all, but if I look in my repository, all I have is an empty folder rather than the actual contents of the submodule&#8217;s repository. In order to fill in the submodule&#8217;s path with the files from the external repository, you must first initialize the submodules and then update them.</p>
<p>First, we need to initialize the submodule(s). We can do that with the following command:</p>
<div class="code"><strong>$ git submodule init</strong><br />
Submodule &#8216;lib/billboard&#8217; (git@mygithost:billboard) registered for path &#8216;lib/billboard&#8217;</div>
<p>Then we need to run the update in order to pull down the files.</p>
<div class="code"><strong>$ git submodule update</strong><br />
Initialized empty Git repository in ~/git_dev/SampleTheme/lib/billboard/.git/<br />
remote: Counting objects: 26, done.<br />
remote: Compressing objects: 100% (22/22), done.<br />
remote: Total 26 (delta 5), reused 0 (delta 0)<br />
Receiving objects: 100% (26/26), 17.37 KiB, done.<br />
Resolving deltas: 100% (5/5), done.<br />
Submodule path &#8216;lib/billboard&#8217;: checked out &#8217;1c407cb2315z0847facb57d79d680f88ca004332&#8242;</div>
<p>Looking in the lib/billboard directory now shows a nice listing of the needed files.</p>
<h3>Removing Submodules</h3>
<p>What happens if we need to remove a submodule? Maybe I made a mistake. It could also be that the design of the project has changed, and the submodules need to change with it. No problem, I&#8217;ll simply run &#8220;<strong>git submodule rm [submodule path]</strong>&#8221; and everything will be great, right?</p>
<p>Unfortunately, this is wrong. Git does not have a built in way to remove submodules. Hopefully this will be resolved in the future, because we now have to do submodule removal manually.</p>
<p>Sticking with the example, we&#8217;ll remove the lib/billboard module from SampleTheme. All the instructions will be run from the working directory of the SampleTheme repository. In order, we need to do the following:</p>
<ol>
<li>Remove the submodule&#8217;s entry in the .gitmodules file.Since lib/billboard is the only submodule in the SampleTheme repository, we can simply remove the file entirely by running &#8220;git rm lib/billboard&#8221;.If lib/billboard isn&#8217;t the only submodule, the .gitmodules file will have to be modified by hand. Open it up in vi, or your favorite text editory, and remove the three lines relevant to the submodule being removed. In this case, these lines will be removed:
<div class="code">[submodule "lib/billboard"]<br />
path = lib/billboard<br />
url = git@mygithost:billboard</div>
</li>
<li>Remove the submodule&#8217;s entry in the .git/config. This step isn&#8217;t strictly necessary, but it does keep your config file tidy and will help prevent problems in the future.The submodule&#8217;s entry in .git/config will only be present if you&#8217;ve run &#8220;git submodule init&#8221; on the repository. If you haven&#8217;t, you can skip this step.In this example, the following lines will be removed:
<div class="code">[submodule "billboard"]<br />
url = git@mygithost:billboard</div>
</li>
<li>Remove the path created for the submodule. This one is easy. Simply run &#8220;<strong>git rm &#8211;cached [plugin path]</strong>&#8220;. In this example, I will run &#8220;<strong>git rm &#8211;cached lib/billboard</strong>&#8220;.As I&#8217;ve seen noted elsewhere, do not put a trailing slash as the command will fail. For example, if I run &#8220;<strong>git rm &#8211;cached lib/billboard/</strong>&#8220;, I get an error: &#8220;<strong>fatal: pathspec &#8216;lib/billboard/&#8217; did not match any files</strong>&#8220;.</li>
</ol>
<h3>Updating Submodules</h3>
<p>There is an aspect about submodules that some may not realize when first working with Git submodules. When you add the submodule, the most recent commit of the submodule is stored in the main repository&#8217;s index. That means that as the code in the submodule&#8217;s repository updates, the same code will still be pulled on the repositories relying on the submodule.</p>
<p>This makes a lot of sense when you consider how your code will have been tested and verified (or at least should be) against a specific version of the submodule code, but the main repository&#8217;s code may not work well with new submodule updates before the changes are tested.</p>
<p>Unfortunately, like removing submodules, Git does not make it clear how to update a submodule to a later commit. Fortunately though, it&#8217;s not that tough.</p>
<ol>
<li>Initialize the repository&#8217;s submodules by running &#8220;<strong>git submodule init</strong>&#8221; followed by &#8220;<strong>git submodule update</strong>&#8220;.</li>
<li>Change into the submodule&#8217;s directory. In this example, &#8220;<strong>cd lib/billboard</strong>&#8220;.</li>
<li>The submodule repositories added by &#8220;<strong>git submodule update</strong>&#8221; are  &#8220;headless&#8221;. This means that they aren&#8217;t on a current branch.To fix this, we simply need to switch to a branch. In this example, that would be the master branch. We switch with the following command: &#8220;<strong>git checkout master</strong>&#8220;.</li>
<li>Next, we simply need to update the repository to the latest checkout. We can do that with a pull: &#8220;<strong>git pull</strong>&#8220;.</li>
<li>Now switch back to the root working directory of the repository. In our example, we are two directories in, so we run &#8220;<strong>cd ../..</strong>&#8220;.</li>
<li>Everything is now ready to be commit and pushed back in (if there is a remote repository to push to that is). If you run &#8220;<strong>git status</strong>&#8220;, you&#8217;ll notice that the path to the submodule is listed as modified. This is what you should expect to see. Simply add the path to be commit and do a commit. When you do the commit, the index will update the commit string for the submodule.</li>
</ol>
<h3>Closing Thoughts</h3>
<p>I&#8217;ve learned a lot in my short time with Git. Expect to see more details about working with Git in the future. I have a series of pitfalls I&#8217;ve discovered that I should organize together and post about. I&#8217;ve also created some really slick scripts to help me automate numerous things when working with the repositories that I&#8217;d like to share.</p>
<p>If there is anything specfic you&#8217;d like to know about Git, please add a comment or <a href="http://chrisjean.com/contact/" target="_blank">contact me</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>MySQL Natural Sort Order By on Non-Numeric Field Type</title>
		<link>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/</link>
		<comments>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 05:00:45 +0000</pubDate>
		<dc:creator>gaarai</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1408</guid>
		<description><![CDATA[I recently worked on a project where I had to sort a set of rows returned from a MySQL query. The problem is that most of the data in the field being sorted is numeric yet the field type is varchar since some of the entries contained characters. The reason that this is a problem [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I recently worked on a project where I had to sort a set of rows returned from a MySQL query. The problem is that most of the data in the field being sorted is numeric yet the field type is varchar since some of the entries contained characters.</p>
<p>The reason that this is a problem is that MySQL sorts character fields using a method that will produce undesirable results with numeric data. For example, sorting 4, 10, and 50 as character data produces 10, 4, and 50. In most applications, this is highly undesirable.</p>
<p>The solution to this is to force a sorting order that is commonly referred to as a natural sort. Natural sort is just a term that refers to how humans would commonly sort a set of information (numbers as numbers and non-numeric characters alphabetically). Fortunately, this isn&#8217;t difficult to achieve in MySQL.</p>
<p><span id="more-1408"></span>To further illustrate the problem, here is a simple table description:</p>
<pre>&gt; DESC SampleData;
<table border="0">
<tbody>
<tr>
<th><b>Field</b></th>
<th><b>Type</b></th>
</tr>
<tr>
<td>data_char&nbsp;</td>
<td>varchar(5)</td>
</tr>
</tbody>
</table>
</pre>
<p>I filled up the table with sample data. The following example query and resulting data shows the problem clearly:</p>
<pre>&gt; SELECT * FROM SampleData ORDER BY data_char;
<table border="0">
<tbody>
<tr>
<th><b>data_char</b></th>
</tr>
<tr>
<td>10</td>
</tr>
<tr>
<td>11</td>
</tr>
<tr>
<td>120</td>
</tr>
<tr>
<td>21</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>a1</td>
</tr>
</tbody>
</table>
</pre>
<p>As you can see, the results aren&#8217;t exactly usable. If we simply modify the order by declaration slightly (add &#8220;+0&#8243; to the order by field), you can force MySQL to sort the field naturally.</p>
<pre>&gt; SELECT * FROM SampleData ORDER BY data_char+0;
<table border="0">
<tbody>
<tr>
<th><b>data_char</b></th>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>10</td>
</tr>
<tr>
<td>11</td>
</tr>
<tr>
<td>21</td>
</tr>
<tr>
<td>120</td>
</tr>
<tr>
<td>a1</td>
</tr>
</tbody>
</table>
</pre>
<p>There you have it. To force a natural sort, just add a 0 onto the field you wish to be naturally sorted.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
