<?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>Chuck&#039;s Musings</title>
	<atom:link href="http://blog.chuckcerrillo.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.chuckcerrillo.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 21 Feb 2010 18:43:40 +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>It&#8217;s been a while</title>
		<link>http://blog.chuckcerrillo.com/2010/02/its-been-a-while/</link>
		<comments>http://blog.chuckcerrillo.com/2010/02/its-been-a-while/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 18:38:43 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Updates]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[car]]></category>
		<category><![CDATA[d90]]></category>
		<category><![CDATA[hyundai]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[nikon]]></category>
		<category><![CDATA[photography]]></category>
		<category><![CDATA[slr]]></category>
		<category><![CDATA[tucson]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=131</guid>
		<description><![CDATA[I'm doing my part in helping the economy, haha!]]></description>
			<content:encoded><![CDATA[<p>My last entry is dated January 12, 2010&#8230; hah! I&#8217;ve been too busy with work to write about anything in a while.</p>
<p>Many of my more recent entries were about my computer/electronics cravings. I mentioned something about going <a href="http://blog.chuckcerrillo.com/2009/10/the-itch-part-2/">socket AM3</a> but I instead ended up with a LGA1156 Core i5 setup. I also changed a lot of my computer&#8217;s components amongst other things, got a <a href="http://worldwide.hyundai.com/web/Showroom/tucson_focus.html">new car</a>, bought a Nintendo Wii console. Finally, I&#8217;m planning to get myself an SLR next month (a Nikon D90).</p>
<p>Now that I&#8217;m on the topic of &#8220;new stuff&#8221; and &#8220;work&#8221;, I forgot to mention here that I&#8217;m now working for <a href="http://www.becr8v.com">cr8v Web Solutions</a> still as a PHP Web Developer. I still have the same home-based work arrangement as I did with Zallas; we also have the same work shift, migration to the new company was pretty painless as far as I am concerned.</p>
<p>I&#8217;m pretty much trying to enjoy the fruits of my labor while I still can, because I won&#8217;t be able to do these stuff once I&#8217;ve decided to settle down&#8230;</p>
<p>I hope my D90 purchase would be the last of this recent string of purchases, haha, I really need to start saving for real.</p>
<p>Now that I mention it, I really should set up a photo gallery section soon to make use of all this space.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2010/02/its-been-a-while/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Year, New Stuff</title>
		<link>http://blog.chuckcerrillo.com/2010/01/new-year-new-stuff/</link>
		<comments>http://blog.chuckcerrillo.com/2010/01/new-year-new-stuff/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 14:44:09 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[Updates]]></category>
		<category><![CDATA[chuck]]></category>
		<category><![CDATA[chuck cerrillo]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[new year]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=128</guid>
		<description><![CDATA[New year, new goals]]></description>
			<content:encoded><![CDATA[<p>Hey, it&#8217;s been a while since I laid my hands on my blog. I&#8217;ve been too busy with work. I guess that&#8217;s a good thing. Yes I&#8217;m still alive, haha!</p>
<p>I was planning on adding new stuff here but I never got around it due to deadlines at work, but I&#8217;ll eventually get to it.</p>
<p>I&#8217;ve been spending much of my time coding server-side, so I figured I&#8217;ll drop my Mootools training for now and focus on cURL. When I do start messing with that, I&#8217;ll make sure to post my progress here.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2010/01/new-year-new-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Itch &#8211; Part 2</title>
		<link>http://blog.chuckcerrillo.com/2009/10/the-itch-part-2/</link>
		<comments>http://blog.chuckcerrillo.com/2009/10/the-itch-part-2/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 14:57:19 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[AM3]]></category>
		<category><![CDATA[AMD]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[DDR3]]></category>
		<category><![CDATA[Phenom]]></category>
		<category><![CDATA[upgrade]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=125</guid>
		<description><![CDATA[Ditching my dual core to go for a quad-core.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m looking into selling my current CPU-Mobo-Ram trio and build myself an AM3 rig. Why AM3 and not Core i7? Well, it&#8217;s kinda hard to source the parts locally, and if they are available, they&#8217;re expensive despite making compromises to the setup. I&#8217;m still planning on keeping my BFG 8800GT, and besides, the onboard Radeon HD4200 on the 785G motherboard would make a great backup video when I do intend to upgrade my videocard as well.</p>
<p>Anyway, I&#8217;ve decided to go with the following setup &#8211; an AMD Phenom II X4 965 cpu, an AM3 motherboard based on the AMD 785G / SB710 chipset, and 2 sticks of 2GB DDR3 memory.</p>
<p>I&#8217;m still trying to decide whether I should skip the Phenom 955 and go directly to 965. It&#8217;s only a 200MHz difference with the 965 costing P1,250 more (about $26).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2009/10/the-itch-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The itch</title>
		<link>http://blog.chuckcerrillo.com/2009/10/the-itch/</link>
		<comments>http://blog.chuckcerrillo.com/2009/10/the-itch/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 00:57:51 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[chuck cerrillo]]></category>
		<category><![CDATA[scratch]]></category>
		<category><![CDATA[upgrade itch]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=122</guid>
		<description><![CDATA[Should I scratch it?]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since my last post&#8230; almost a month actually. It&#8217;s just that I&#8217;ve either been too busy with work, or enjoying work too much that I kinda neglected doing my regular stuff here for a while&#8230;</p>
<p>With that said, I&#8217;ve been working too much and haven&#8217;t had the chance to enjoy my salary yet&#8230; well, one of the first things that came to mind was getting a camcorder (which, actually is already happening, haha!), secondly, my computer upgrade itch.</p>
<p>Damnit, I&#8217;m eyeing the Samsung T260HD LCD monitor, and I&#8217;ve also been itching to upgrade my processor, motherboard and RAM.</p>
<p>Christmas is approaching, all in due time I guess.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2009/10/the-itch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Canvas</title>
		<link>http://blog.chuckcerrillo.com/2009/09/my-canvas/</link>
		<comments>http://blog.chuckcerrillo.com/2009/09/my-canvas/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 05:38:10 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[Updates]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[chuck cerrillo]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[section]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=119</guid>
		<description><![CDATA[Added a new section named "Canvas".]]></description>
			<content:encoded><![CDATA[<p>I have recently opened yet another section for my website, named &#8220;<a href="http://canvas.chuckcerrillo.com">Canvas</a>&#8220;. This is basically my testing area for my Mootools experiments.</p>
<p>If you&#8217;ve seen what I have so far, you might&#8217;ve guessed what I am aiming for. That&#8217;s right, I&#8217;m simulating a window-based workspace. For now the content is static but I&#8217;ll eventually fill it up with dynamic content once I am comfortable with AJAX.</p>
<p>That makes  3 major sub-areas of my website,</p>
<ol>
<li><a href="http://blog.chuckcerrillo.com">My blog</a> &#8211; you&#8217;re currently reading this</li>
<li><a href="http://thedirtlab.chuckcerrillo.com">TheDirtLab</a> &#8211; a repository of my recent scripts and experiments</li>
<li><a href="http://canvas.chuckcerrillo.com">Canvas</a> &#8211; my window-system experiment</li>
</ol>
<p>I might even probably open up a section for multimedia, but I don&#8217;t see it anytime soon, lol.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2009/09/my-canvas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TheDirtLab is coming up soon</title>
		<link>http://blog.chuckcerrillo.com/2009/09/thedirtlab-is-coming-up-soon/</link>
		<comments>http://blog.chuckcerrillo.com/2009/09/thedirtlab-is-coming-up-soon/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 13:49:59 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[Updates]]></category>
		<category><![CDATA[coming soon]]></category>
		<category><![CDATA[thedirtlab]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=116</guid>
		<description><![CDATA[Just a framework for now, but I'll get the content up soon.]]></description>
			<content:encoded><![CDATA[<p>It has been a while since my last entry, being busy with work and all, so I&#8217;ve decided to spend some time this weekend working on the basic framework for <a href="http://thedirtlab.chuckcerrillo.com">TheDirtLab</a>.</p>
<p>I&#8217;ve already written some content for it in my past entries (scripts, that is), so at least it won&#8217;t be empty when it goes up. Hopefully I&#8217;d be able to publish them by the end of the day or early Monday.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2009/09/thedirtlab-is-coming-up-soon/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More minor website updates</title>
		<link>http://blog.chuckcerrillo.com/2009/09/more-minor-website-updates/</link>
		<comments>http://blog.chuckcerrillo.com/2009/09/more-minor-website-updates/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 12:49:54 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[chuck cerrillo]]></category>
		<category><![CDATA[contact]]></category>
		<category><![CDATA[mailbox]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[transparent]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=113</guid>
		<description><![CDATA[If you've been to the front page recently, you'll know what I'm talking about!]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve visited the front page recently, you&#8217;d have probably noticed the mailbox on the far right side of the lawn. This mailbox will be linked to a contact form (which I haven&#8217;t started coding in yet, haha!).</p>
<p>Also, I&#8217;ve made slight modifications to the top navigation bar. The menus are now semi-transparent. I&#8217;ve yet to decide if I&#8217;ll keep it that way or revert to the old solid white and gray menus.</p>
<p>Aside from that, I am hoping to be able to find the time to work on the other planned features of my website. Please keep coming back for updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2009/09/more-minor-website-updates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to: Insert a new field into a dynamic array</title>
		<link>http://blog.chuckcerrillo.com/2009/09/how-to-insert-a-new-field-into-a-dynamic-array/</link>
		<comments>http://blog.chuckcerrillo.com/2009/09/how-to-insert-a-new-field-into-a-dynamic-array/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 01:59:14 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[PHP and MySQL]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=103</guid>
		<description><![CDATA[Inserting new fields into a dynamic array.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been busy with work &#8211; deadlines and all, so it&#8217;s been a while since my last entry. For now I&#8217;ll just share a quick tip. How to <em>Insert a new field into a dynamic array</em>.</p>
<p>If you&#8217;ve been reading the code snippets I&#8217;ve been posting thus far, you&#8217;ll notice that I am doing this thing a lot. Anyway, here&#8217;s a little background on this situation.</p>
<p>Let&#8217;s say you just retrieved records from your database table and stored them into an associative array named <code class="codecolorer php default"><span class="php"><span style="color: #000088;">$results</span></span></code>, now you want to insert an extra field for each row but you don&#8217;t know how to to assign them since you don&#8217;t know how to walk through the array.</p>
<p>Let&#8217;s say you have this array:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Array<br />
(<br />
&nbsp; &nbsp; [0] =&gt; Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_id] =&gt; 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_name] =&gt; Chuck<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_level] =&gt; 3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [birthdate] =&gt; 1984-09-15<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
<br />
&nbsp; &nbsp; [1] =&gt; Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_id] =&gt; 2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_name] =&gt; Blah<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_level] =&gt; 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [birthdate] =&gt; 2001-01-01<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
<br />
&nbsp; &nbsp; [2] =&gt; Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_id] =&gt; 3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_name] =&gt; New user<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_level] =&gt; 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [birthdate] =&gt; 2002-10-30<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
<br />
&nbsp; &nbsp; [3] =&gt; Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_id] =&gt; 4<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_name] =&gt; Random guy<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_level] =&gt; 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [birthdate] =&gt; 1992-07-21<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
<br />
)</div></div>
<p>This means, each row has the following fields &#8211; user_id, user_name, user_level, and birthdate.<br />
Now, let&#8217;s say we wanted to create a new field named &#8220;age&#8221; and store it in the same array. Here&#8217;s my preferred method of doing this:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$index</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'age'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> get_age<span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'birthdate'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Take note that to maintain the abstraction of the code, I just called a function named <code class="codecolorer php default"><span class="php">get_age<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span></code>. Remember that there is no such function so you&#8217;ll have to code that in to make it work. For completeness sake, here&#8217;s how I&#8217;d probably do it:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Accepts 2 parameters, $bday and $now. $bday is of </span><br />
<span style="color: #666666; font-style: italic;">// the 'YYYY-MM-DD' format. The result is based on the </span><br />
<span style="color: #666666; font-style: italic;">// difference between $now and $bday converted to</span><br />
<span style="color: #666666; font-style: italic;">// years. $now is optional. If it is not supplied, it uses </span><br />
<span style="color: #666666; font-style: italic;">// the current time. This is not exactly accurate since I</span><br />
<span style="color: #666666; font-style: italic;">// just indiscriminately used 365.25 days in my calculation.</span><br />
<span style="color: #666666; font-style: italic;">// To improve, I'll have to detect leap years and just</span><br />
<span style="color: #666666; font-style: italic;">// add 1 day to that, instead of 1/4 days to every year.</span><br />
<span style="color: #000000; font-weight: bold;">function</span> get_age<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bday</span><span style="color: #339933;">,</span> <span style="color: #000088;">$now</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000088;">$bday</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strtotime"><span style="color: #990000;">strtotime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bday</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000088;">$now</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$now</span><span style="color: #009900;">&#41;</span>?<a href="http://www.php.net/strtotime"><span style="color: #990000;">strtotime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$now</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><a href="http://www.php.net/mktime"><span style="color: #990000;">mktime</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <a href="http://www.php.net/floor"><span style="color: #990000;">floor</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$now</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$bday</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>60<span style="color: #339933;">*</span>60<span style="color: #339933;">*</span>24<span style="color: #339933;">*</span>365<span style="color: #339933;">.</span>25<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Anyway, after doing all that, you will get this result:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Array<br />
(<br />
&nbsp; &nbsp; [0] =&gt; Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_id] =&gt; 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_name] =&gt; Chuck<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_level] =&gt; 3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [birthdate] =&gt; 1984-09-15<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [age] =&gt; 24<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
<br />
&nbsp; &nbsp; [1] =&gt; Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_id] =&gt; 2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_name] =&gt; Blah<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_level] =&gt; 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [birthdate] =&gt; 2001-01-01<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [age] =&gt; 8<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
<br />
&nbsp; &nbsp; [2] =&gt; Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_id] =&gt; 3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_name] =&gt; New user<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_level] =&gt; 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [birthdate] =&gt; 2002-10-30<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [age] =&gt; 6<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
<br />
&nbsp; &nbsp; [3] =&gt; Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_id] =&gt; 4<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_name] =&gt; Random guy<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [user_level] =&gt; 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [birthdate] =&gt; 1992-07-21<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [age] =&gt; 17<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
<br />
)</div></div>
<p>As an aside, you could probably use <a href="http://us.php.net/manual/en/function.array-walk.php"><code class="codecolorer php default"><span class="php"><a href="http://www.php.net/array_walk"><span style="color: #990000;">array_walk</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a> to achieve something similar, but this method is way simpler. I hope this has been helpful to you!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2009/09/how-to-insert-a-new-field-into-a-dynamic-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Juggling time zones</title>
		<link>http://blog.chuckcerrillo.com/2009/09/juggling-time-zones/</link>
		<comments>http://blog.chuckcerrillo.com/2009/09/juggling-time-zones/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 00:30:14 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[PHP and MySQL]]></category>
		<category><![CDATA[gmdate]]></category>
		<category><![CDATA[gmt]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[offsets]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[strtotime]]></category>
		<category><![CDATA[timestamp]]></category>
		<category><![CDATA[timezones]]></category>
		<category><![CDATA[utc]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=100</guid>
		<description><![CDATA[If you're thinking of writing calendars, you better watch out for timezones.]]></description>
			<content:encoded><![CDATA[<p>Handling times for different timezones is one of the usual things I had to face with every project that has in one way or the other involves the element of time.</p>
<p>The usual projects I work on store dates into a <code class="codecolorer sql default"><span class="sql">datetime</span></code> field in the database. This means that the date must use the <code class="codecolorer text default"><span class="text">YYYY-MM-DD HH:MM:SS</span></code> format (e.g. 2009-09-03 07:45:00).</p>
<p>One of the first things you&#8217;d want to do is to let the user specify a timezone setting for that user account (assuming this is in a multi-user environment, as most web applications are). You could view all the timezones using this code:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;ul&gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span>DateTimeZone<span style="color: #339933;">::</span><span style="color: #004000;">listAbbreviations</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$timezone_abbreviation</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$timezones</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timezones</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$timezone</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timezone</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'timezone_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$timezone_abbreviation</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' - '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$timezone</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'timezone_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;li&gt;Uses DST: '</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timezone</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dst'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">===</span><span style="color: #009900; font-weight: bold;">TRUE</span>?<span style="color: #0000ff;">'Yes'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'No'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/li&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;li&gt;Offset: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$timezone</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'offset'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/li&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span></div></div>
<p>You could modify the code above to create a drop-down list of the different timezones to make it easier for the user to pick a timezone (because simply writing GMT+8 or UTC+8 might be confusing for some people).</p>
<p>Next, we will have to convert all of our stored dates into a single timezone, for simplicity, I use GMT/UTC as a reference timezone (since it is easy to add timezone offsets to it). If you store your dates in a <code class="codecolorer sql default"><span class="sql">datetime</span></code> field, you can perform the following conversion after retrieving the timestamp from the database:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// let's assume $parsedtime is the entry we have in the database</span><br />
<span style="color: #666666; font-style: italic;">// and $offset is the timezone offset we got based on the user's settings</span><br />
<span style="color: #000088;">$parsedtime</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'2009-09-15 12:00:00'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> 8<span style="color: #339933;">*</span>60<span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// this is GMT +8</span><br />
<span style="color: #666666; font-style: italic;">// get the GMT counterpart of the parsedtime</span><br />
<span style="color: #000088;">$unix_time</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strtotime"><span style="color: #990000;">strtotime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parsedtime</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' GMT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <a href="http://www.php.net/gmdate"><span style="color: #990000;">gmdate</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m d Y h:iA'</span><span style="color: #339933;">,</span><span style="color: #000088;">$unix_time</span><span style="color: #339933;">-</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// displays: 09 15 2009 04:00AM</span></div></div>
<p>So that means, 12nn of September 15, 2009 is 4am of September 15, 2009 in GMT/UTC.</p>
<p>Let&#8217;s say we had a Calendar application, and you wanted to set an alarm for 6pm on that same day. You could do the something like the this (assuming you wrote some sort of class for this thing):</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$reminder</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Reminder<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'2009-09-15 18:00:00'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Dinner with the family'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$reminder</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeLeft</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Since the current date and time was 12nn of September 15, 2009, this means that the above reminder will display &#8220;6 hours left&#8221;, depending on how the <code class="codecolorer php default"><span class="php">timeLeft<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> method is formatted.</p>
<p>If we didn&#8217;t convert the date into a standard timezone, this will force our functions to use the server&#8217;s timezone setting and that might not be what you want.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2009/09/juggling-time-zones/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Regular expressions in MySQL</title>
		<link>http://blog.chuckcerrillo.com/2009/09/regular-expressions-in-mysql/</link>
		<comments>http://blog.chuckcerrillo.com/2009/09/regular-expressions-in-mysql/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 05:19:32 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[PHP and MySQL]]></category>
		<category><![CDATA[chuck cerrillo]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.chuckcerrillo.com/?p=92</guid>
		<description><![CDATA[Using regular expressions in your SQL statements helps to keep it simple.]]></description>
			<content:encoded><![CDATA[<p><a href="http://mysql.com"><img style="float: left" src="http://dev.mysql.com/common/logos/logo_mysql_sun_a.gif" alt="MySQL" /></a> I&#8217;ve been using MySQL for the better part of the past 6 years so it comes as a pleasant surprise when I found out last month that it can do regular expressions within its SQL!</p>
<p>I&#8217;m not sure about the other databases, the last time I&#8217;ve used Oracle was around 2004-2005 during my college days, so I can&#8217;t really say if this is a MySQL-exclusive feature or something along those lines. I&#8217;m pretty positive that this isn&#8217;t standard SQL though, since we never had such lessons back in college.</p>
<p>Anyway, if you&#8217;re familiar with SQL and string matching within SQL, it makes use of the <code class="codecolorer sql default"><span class="sql"><span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'[string]'</span></span></code> clause. Where [string] is the string to be searched for. Optionally, you could also use wildcards like _ (underscore), % (percent), [charlist] (character list) or [^charlist] (negated character list) or a combination of those to match string fragments. Unfortunately this has also been one of the major points of entry for hacking/hijacking a database-driven website, via <a href="http://en.wikipedia.org/wiki/SQL_injection">SQL injection</a>. Due to this vulnerability, I&#8217;ve either been using heavy data validation, or store encoded data, or at times, avoiding this altogether&#8230; but I digress.</p>
<p>Using regex in my SQL queries is a godsend. It helps reduce my data processing and validation overhead.</p>
<p>MySQL supports the use of almost all POSIX regex  metacharacters via the <code class="codecolorer sql default"><span class="sql"><span style="color: #993333; font-weight: bold;">REGEXP</span></span></code> or <code class="codecolorer sql default"><span class="sql"><span style="color: #993333; font-weight: bold;">RLIKE</span></span></code> clause (or a negation using <code class="codecolorer sql default"><span class="sql"><span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">REGEXP</span></span></code> or <code class="codecolorer sql default"><span class="sql"><span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">RLIKE</span></span></code>).</p>
<p><strong>The following list describes some characteristics of extended regular expressions:</strong></p>
<ul>
<li>“.” matches any single character.</li>
<li>A character class “[...]” matches any character within the brackets. For example, “[abc]” matches “a”, “b”, or “c”. To name a range of characters, use a dash. “[a-z]” matches any letter, whereas “[0-9]” matches any digit.</li>
<li>“*” matches zero or more instances of the thing preceding it. For example, “x*” matches any number of “x” characters, “[0-9]*” matches any number of digits, and “.*” matches any number of anything.</li>
<li>A REGEXP pattern match succeeds if the pattern matches anywhere in the value being tested. (This differs from a LIKE pattern match, which succeeds only if the pattern matches the entire value.)</li>
<li>To anchor a pattern so that it must match the beginning or end of the value being tested, use “^” at the beginning or “$” at the end of the pattern.</li>
</ul>
<p>Let&#8217;s start with the traditional <code class="codecolorer sql default"><span class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">...</span>  <span style="color: #993333; font-weight: bold;">LIKE</span></span></code> query. Here&#8217;s a query that selects all animals whose name begins with &#8220;ant&#8221;</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> name<br />
<br />
<span style="color: #993333; font-weight: bold;">FROM</span> animals<br />
<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'ant%'</span></div></div>
<p>The results could be something like this:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">name<br />
<br />
<span style="color: #808080; font-style: italic;">---------</span><br />
<br />
ant<br />
<br />
anteater<br />
<br />
antelope<br />
<br />
<span style="color: #66cc66;">...</span></div></div>
<p>A regex version of that would be:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> name<br />
<br />
<span style="color: #993333; font-weight: bold;">FROM</span> animals<br />
<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">REGEXP</span> <span style="color: #ff0000;">'^ant'</span></div></div>
<p>So far they look similar&#8230; but, say, what if you wanted to use a complex rule like: &#8220;select all animals whose names starts with either &#8216;a&#8217; or &#8216;c&#8217; and ends with either &#8216;t&#8217; or &#8216;p&#8217;.  It would look messy if you do it this way:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> name<br />
<br />
<span style="color: #993333; font-weight: bold;">FROM</span> animals<br />
<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'a%t'</span><br />
<br />
<span style="color: #993333; font-weight: bold;">OR</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'a%p'</span><br />
<br />
<span style="color: #993333; font-weight: bold;">OR</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'c%t'</span><br />
<br />
<span style="color: #993333; font-weight: bold;">OR</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'c%p'</span></div></div>
<p>However with regex, it is as simple as this:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> name<br />
<br />
<span style="color: #993333; font-weight: bold;">FROM</span> animals<br />
<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">REGEXP</span> <span style="color: #ff0000;">'^[ac].*[tp]$'</span></div></div>
<p>Imagine if your filtering conditions were much more complex. It&#8217;s not hard to see how regexp can help with that!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chuckcerrillo.com/2009/09/regular-expressions-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
