<?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>&#60;Code Zen /&#62; &#187; Programming</title>
	<atom:link href="http://www.code-zen.net/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.code-zen.net</link>
	<description>Peter Anselmo&#039;s Home on the Web</description>
	<lastBuildDate>Wed, 12 Oct 2011 01:11:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Dynamic Display of the Alphabet with PHP</title>
		<link>http://www.code-zen.net/2008/dynamic-display-of-the-alphabet-with-php/</link>
		<comments>http://www.code-zen.net/2008/dynamic-display-of-the-alphabet-with-php/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 21:14:07 +0000</pubDate>
		<dc:creator>Peter Anselmo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ascii]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://code-zen.net/?p=138</guid>
		<description><![CDATA[Here&#8217;s a neat trick I recently used: Say you want to the display the alphabet on your web page.  The most likely scenario being for paging links to organize a directory of people or businesses. PHP has a chr() function, which displays the ASCII character for any given integer. Rather than looping through an array [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a neat trick I recently used: Say you want to the display the alphabet on your web page.  The most likely scenario being for paging links to organize a directory of people or businesses. PHP has a chr() function, which displays the ASCII character for any given integer.</p>
<p>Rather than looping through an array with 26 values, or worse yet, typing out 26 lines of code, just loop through the display code 26 times.</p>
<pre>&lt;?php
for ($i=65; $i&lt;=90; $i++) {
 echo chr($i);
}
?&gt;</pre>
<p>For those not familiar with ASCII mappings, values 65-90 represent the uppercase letters A-Z.  Alternately, you could use the values 97-122 for lowercase a-z.  If you wanted to mix the two (say to display uppercase, but use lowercase in the link) just use the strtoupper() or strtolower() functions inside the loop.  Here&#8217;s a more applicable sample:</p>
<pre>&lt;?php
for ($i=97; $i&lt;=122; $i++) {
 $x = chr($i);
 echo '&lt;a href="memberlist.php?alpha=' . $x . '&gt;' . strtoupper($x) . '&lt;/a&gt;';
}
?&gt;

You can see an example of both <a href="http://code-zen.net/sandbox/alphabet.php" target="_blank">applied here</a>.</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F&amp;title=Dynamic+Display+of+the+Alphabet+with+PHP" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F&amp;title=Dynamic+Display+of+the+Alphabet+with+PHP" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F&amp;title=Dynamic+Display+of+the+Alphabet+with+PHP" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F&amp;headline=Dynamic+Display+of+the+Alphabet+with+PHP" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Dynamic+Display+of+the+Alphabet+with+PHP&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Dynamic+Display+of+the+Alphabet+with+PHP&amp;u=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Dynamic+Display+of+the+Alphabet+with+PHP&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Dynamic+Display+of+the+Alphabet+with+PHP&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Dynamic+Display+of+the+Alphabet+with+PHP&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F&amp;title=Dynamic+Display+of+the+Alphabet+with+PHP&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fdynamic-display-of-the-alphabet-with-php%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.code-zen.net/2008/dynamic-display-of-the-alphabet-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding Music</title>
		<link>http://www.code-zen.net/2008/coding-music/</link>
		<comments>http://www.code-zen.net/2008/coding-music/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 05:11:19 +0000</pubDate>
		<dc:creator>Peter Anselmo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[delerium]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[shpongle]]></category>
		<category><![CDATA[trance]]></category>
		<category><![CDATA[zen]]></category>

		<guid isPermaLink="false">http://code-zen.net/?p=155</guid>
		<description><![CDATA[Music is a big part of programming.  Nothing gets me zen faster than immersion in a good back beat.  As such, I&#8217;d like to pass on a few genres and artists that I think stand out as being conducive to cranking out code. Trance: By far, I spend the most time listening to Eric Jordan.  [...]]]></description>
			<content:encoded><![CDATA[<p>Music is a big part of programming.  Nothing gets me zen faster than immersion in a good back beat.  As such, I&#8217;d like to pass on a few genres and artists that I think stand out as being conducive to cranking out code.</p>
<p><strong>Trance:</strong></p>
<div id="attachment_152" class="wp-caption alignleft" style="width: 130px"><a href="http://www.neverrain.com"><img class="size-thumbnail wp-image-152" title="engage_august2008web" src="http://code-zen.net/wp-content/uploads/2008/12/engage_august2008web-150x150.jpg" alt="Eric Jordan" width="120" height="120" /></a><p class="wp-caption-text">Eric Jordan</p></div>
<p>By far, I spend the most time listening to Eric Jordan.  His trance mixes are stunning.  They are always creative, drawing from his vast knowlege of obscure, but impressive tracks.  He is a master at creating a mood, evoking emotion, and pulling the listener in.  Every month he posts a new mix on his website: <a href="http://www.neverrain.com" target="_blank">neverrain.com</a>, available for free to download.  His mixes tend to have more subtle melodies, and less vocals, so I find them extra conducive to zoning out and programming complex algorithms.</p>
<div style="visibility:hidden;clear:both;">asd</div>
<p><strong style="clear:left;">Vocal Trance:</strong></p>
<div id="attachment_156" class="wp-caption alignleft" style="width: 120px"><a href="http://www.generationtrance.com" target="_blank"><img class="size-thumbnail wp-image-156" title="dg_gt" src="http://code-zen.net/wp-content/uploads/2008/12/dg_gt.gif" alt="DJ GT" width="110" height="60" /></a><p class="wp-caption-text">DJ GT</p></div>
<p>DJ GT takes a similar approach, creating hour long mixes and posting them for free on his website, <a title="Generation Trance" href="http://www.generationtrance.com" target="_blank">generationtrance.com</a>. He is equally talented, although his track lists tend to be slightly more mainstream.  All of the songs he uses contain lyrics, which makes the mixes a little more structured and digestable for those not as used to electronic music.  I&#8217;ll throw one of his many tracks in the queue when I want something more upbeat to tap my feet to.</p>
<div style="visibility:hidden;clear:both;">asd</div>
<p><strong style="clear:left;">Psycadelic Trance:</strong></p>
<div id="attachment_161" class="wp-caption alignleft" style="width: 130px"><a href="http://www.amazon.com/Shpongle/e/B000APNMTG/ref=ntt_mus_dp_pel"><img class="size-thumbnail wp-image-161" title="shpongle" src="http://code-zen.net/wp-content/uploads/2008/12/shpongle-150x150.jpg" alt="Shpongle" width="120" height="120" /></a><p class="wp-caption-text">Shpongle</p></div>
<p>Shpongle is group out of the UK that defies description.  Generally, I&#8217;d label it Psy Trance, but you&#8217;ll find heavy influences of world beat, classical, opera, jazz, ska, punk, dub, and half a dozen other genres.  It all adds up to 100% awesome.  Lyrics in their music are not arranged into verses to tell a story, but rather sampled to become part of the ambience and reinforce the mood.  My only wish is that they had more than three albums.</p>
<div style="visibility:hidden;clear:both;">asd</div>
<p><strong style="clear:left;">Dub:</strong></p>
<div id="attachment_163" class="wp-caption alignleft" style="width: 130px"><a href="http://www.amazon.com/O.T.T./e/B001LHNZ1M/ref=ntt_mus_dp_pel"><img class="size-thumbnail wp-image-163" title="ott" src="http://code-zen.net/wp-content/uploads/2008/12/ott-150x150.jpg" alt="O.T.T." width="120" height="120" /></a><p class="wp-caption-text">OTT</p></div>
<p>If I had to describe Dub to someone who hadn&#8217;t heard it, I&#8217;d label it the offspring of Reggae and Trance.  It&#8217;s characterized by a slower tempo than most electronica, with a heavier bassline and more emphasis on the ambience of the music.  Ott&#8217;s first album <a href="http://www.amazon.com/Blumenkraft-OTT/dp/B00008XUSP" target="_blank">Blumenkraft</a> stands out as my favorite mix of any artist mentioned here.  It&#8217;s simply the most powerful weapon against the drone of office background noise I&#8217;ve found.  I save it for when I need to write that recursive function I&#8217;ve been putting off all week.</p>
<div style="visibility:hidden;clear:both;">asd</div>
<p><strong style="clear:left;">Industrial:</strong></p>
<div id="attachment_166" class="wp-caption alignleft" style="width: 130px"><a href="http://www.amazon.com/Civilization-Front-Line-Assembly/dp/B00015HVL0"><img class="size-thumbnail wp-image-166" title="fla" src="http://code-zen.net/wp-content/uploads/2008/12/fla-150x150.jpg" alt="Front Line Assembly" width="120" height="120" /></a><p class="wp-caption-text">Front Line Assembly</p></div>
<p>Two of my favorite artists are Bill Leeb and Rhys Fulber.  They&#8217;ve been making electronic music for two decades, and they&#8217;ve made some of the best.  They&#8217;ve gone under several different names, the most popular being <a href="http://www.amazon.com/Delerium/e/B000APYL9G" target="_blank">Delerium</a> and <a href="http://www.amazon.com/Front-Line-Assembly/e/B000APVP72" target="_blank">Front Line Assembly</a>.  Delerium, like Shpongle, defies description and has gone through several distinct transitions through the years.  I own and love the entire collection, but the music I find best to program to however, are their oldest albums, found <a href="http://www.amazon.com/Archives-Vol-1-Delerium/dp/B00005OAG9" target="_blank">here</a> and <a href="http://www.amazon.com/Archives-Vol-2-Delerium/dp/B00005OAGA" target="_blank">here</a>.  Each of those are a two CD set that compiles all the their earliest releases which are (sadly) no longer available.  The music is very experimental, and it laid the groundwork for the industrial genre.</p>
<div class="mceTemp">Well, that concludes the tour of my favorite programming music.  I hope you enjoyed the trip; be careful opening the overhead bins, as items may have shifted in flight.  I&#8217;m always open for recommendataion, so if you hear a good tune that makes you stop and close your eyes to listen, let me know.</div>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F&amp;title=Coding+Music" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F&amp;title=Coding+Music" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F&amp;title=Coding+Music" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F&amp;headline=Coding+Music" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Coding+Music&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Coding+Music&amp;u=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Coding+Music&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Coding+Music&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Coding+Music&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F&amp;title=Coding+Music&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fcoding-music%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.code-zen.net/2008/coding-music/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Month View Calendar</title>
		<link>http://www.code-zen.net/2008/php-month-view-calendar/</link>
		<comments>http://www.code-zen.net/2008/php-month-view-calendar/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 00:54:21 +0000</pubDate>
		<dc:creator>Peter Anselmo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://code-zen.net/?p=77</guid>
		<description><![CDATA[I recently had to develop a month view Calendar for a website I&#8217;m building.  While such a thing is very common, it presents a number of twists: You can&#8217;t start it on the first of the month &#8211; The first will likely fall mid-week To find the acutual first day of the week, you need [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to develop a month view Calendar for a website I&#8217;m building.  While such a thing is very common, it presents a number of twists:</p>
<ul>
<li>You can&#8217;t start it on the first of the month &#8211; The first will likely fall mid-week</li>
<li>To find the acutual first day of the week, you need to know how many days are in the previous month and count backwards</li>
<li>You cannot assume 4 weeks per month -most have 5 or 6</li>
<li>you will need to use the correct number of days in the month, and then add on the correct number of days of the next month to finish the week</li>
</ul>
<p>After playing with a few algorithms, I decided to represent the month with a 2-dimensional array, one index for each week, and another for each day.  Then, you can put the actual string date in each value, or perhaps an array with that day&#8217;s events.  Without further ado:</p>
<pre>&lt;?php
//CreateMonthView -
//Takes one parameter: a unix timestamp anywhere in the month
function CreateMonthView( $now ) {

    //get numberic day of month (01-31)
    $dayOfMonth = strftime('%d', $now);
    //subtract as approptriate to get to start of month
    $monthStart = $now - (86400 * ($dayOfMonth -1));

    //get numeric day of week (0-6)
    $dayOfWeek = strftime('%w', $monthStart);

    //subtract appropriate number of days to get to the start of the week
    //this will usually be the last part of the previous month
    $calMonthStart = $monthStart - (86400 * $dayOfWeek );

    //initialize variables for while loop
    $thisWeekStart = $calMonthStart;
    $week = 1;
    $monthArray = array();

    //last day of month - text condition for while loop
    $lastDayOfMonth = mktime(23, 59, 59,
                             date("m", $now),
                             date("t", $now),
                             date("Y", $now));

    //foreach week, create a new array to hold the days
    while( $thisWeekStart &lt;= $lastDayOfMonth ) {
        $monthArray[$week] = array();

        //iterate through week - adding each day as a value
        for( $i=0; $i&lt;7; $i++) {
            //get timestamp for each day
            $dayOfWeek = $thisWeekStart + 86400 * $i;
            //convert to a and ISO date - seconds are too precise
            $date = date('Y-m-d',$dayOfWeek);

            //each day will be the value in the array
            $monthArray[$week][] = $date;
        }

        //increment sentinal variable and week counter
        $thisWeekStart = $dayOfWeek + 86400;
        $week++;
    }

    return $monthArray;
}
?&gt;</pre>
<p>Now you may be saying to yourself &#8220;okay, that&#8217;s all fine and good, but it doesn&#8217;t do anything on it&#8217;s own&#8221;, and you&#8217;d be right, it&#8217;s just a function.  To make something happen, you simply need to call it, and display the result.  Here is another snippet that does just that:</p>
<pre>&lt;?php
$month = CreateMonthView( mktime() ); //create the current month

echo '&lt;table&gt;';
foreach( $month as $week ) {
    echo '&lt;tr&gt;';

    foreach ($week as $day ) {
        if( $day == date('Y-m-d') ){
            //apply selector to distinguish today's date
            echo '&lt;td class="today"&gt;';
        } else {
            echo '&lt;td&gt;';
        }
        //reduce the complete ISO date down to the day and display it
        echo substr($day, 8, 2);
        echo '&lt;/td&gt;';
    }
    echo "&lt;/tr&gt;\n";
}
echo '&lt;/table&gt;';
?&gt;</pre>
<p>Viola!  You can certainly copy and paste this code as is, but it&#8217;s not very visually exciting. <a href="http://code-zen.net/sandbox/calendar.php" target="_blank">Here&#8217;s an example</a>. It could definitely use some styling &#8211; but I&#8217;ll leave that up to you.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F&amp;title=PHP+Month+View+Calendar" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F&amp;title=PHP+Month+View+Calendar" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F&amp;title=PHP+Month+View+Calendar" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F&amp;headline=PHP+Month+View+Calendar" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=PHP+Month+View+Calendar&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=PHP+Month+View+Calendar&amp;u=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=PHP+Month+View+Calendar&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=PHP+Month+View+Calendar&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=PHP+Month+View+Calendar&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F&amp;title=PHP+Month+View+Calendar&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fphp-month-view-calendar%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.code-zen.net/2008/php-month-view-calendar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Hash Generator</title>
		<link>http://www.code-zen.net/2008/quick-hash-generator/</link>
		<comments>http://www.code-zen.net/2008/quick-hash-generator/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 16:49:44 +0000</pubDate>
		<dc:creator>Peter Anselmo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://code-zen.net/?p=71</guid>
		<description><![CDATA[I often find myself quickly needing the 1-way encrypted value (hash) of a string. Most often, it&#8217;s to securely store an individual password into a database or script. Rather than temporarily hard-coding the plain text to see what PHP will generate, I wrote a little reusable script to generate hash values. Anyone who might find [...]]]></description>
			<content:encoded><![CDATA[<p>I often find myself quickly needing the 1-way encrypted value (hash) of a string.  Most often, it&#8217;s to securely store an individual password into a database or script.  Rather than temporarily hard-coding the plain text to see what PHP will generate, I wrote a little reusable script to generate hash values.  Anyone who might find it useful can <a href="http://www.code-zen.net/sandbox/hash.php" target="_blank">find it here</a>.  If you&#8217;re paranoid about security, you can find a <a href="https://www.code-zen.net/sandbox/hash.php" target="_blank">secure version here</a>, although you may get a warning about my self-signed certificate.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F&amp;title=Quick+Hash+Generator" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F&amp;title=Quick+Hash+Generator" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F&amp;title=Quick+Hash+Generator" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F&amp;headline=Quick+Hash+Generator" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Quick+Hash+Generator&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Quick+Hash+Generator&amp;u=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Quick+Hash+Generator&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Quick+Hash+Generator&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Quick+Hash+Generator&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F&amp;title=Quick+Hash+Generator&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fquick-hash-generator%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.code-zen.net/2008/quick-hash-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get a Random Row from Database</title>
		<link>http://www.code-zen.net/2008/get-a-random-row-from-database/</link>
		<comments>http://www.code-zen.net/2008/get-a-random-row-from-database/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 01:35:01 +0000</pubDate>
		<dc:creator>Peter Anselmo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://code-zen.net/?p=23</guid>
		<description><![CDATA[I had an app the other day that required a single random row to be displayed from the database. It&#8217;s an easy task, but I tripped on it for a second. Here was my impulse: //Get the total number of rows from the MySQL database $query = "SELECT COUNT(*) as total FROM table"; $result = [...]]]></description>
			<content:encoded><![CDATA[<p>I had an app the other day that required a single random row to be displayed from the database. It&#8217;s an easy task, but I tripped on it for a second. Here was my impulse:</p>
<pre class="content">//Get the total number of rows from the MySQL database
$query = "SELECT COUNT(*) as total FROM table";
$result = mysql_query( $query);
$rows = mysql_fetch_assoc( $result );

//Let PHP choose a random row
//pick a number between 1 &amp; the total
$row = rand(1, $rows['total'])

//Now get that row
$query = "SELECT * FROM table LIMIT($row, 1)";
$result = mysql_query( $query);</pre>
<p>After typing that out, I realized that I had take the long way round the problem. Very similar to taking the Misty Mountain Path rather than the Mines of Moria. Here&#8217;s a better way:</p>
<pre>//Get a random row from the database
$query = "SELECT * FROM table ORDER BY RAND() LIMIT 1";
$result = mysql_query( $query );</pre>
<p>Much better.  Gimley the dwarf would be proud</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F&amp;title=Get+a+Random+Row+from+Database" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F&amp;title=Get+a+Random+Row+from+Database" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F&amp;title=Get+a+Random+Row+from+Database" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F&amp;headline=Get+a+Random+Row+from+Database" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Get+a+Random+Row+from+Database&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Get+a+Random+Row+from+Database&amp;u=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Get+a+Random+Row+from+Database&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Get+a+Random+Row+from+Database&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Get+a+Random+Row+from+Database&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F&amp;title=Get+a+Random+Row+from+Database&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.code-zen.net%2F2008%2Fget-a-random-row-from-database%2F" ><img class="lightsocial_img" src="http://www.code-zen.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.code-zen.net/2008/get-a-random-row-from-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

