<?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>WhyPad &#187; PHP</title>
	<atom:link href="http://www.whypad.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.whypad.com</link>
	<description>Tips, tricks, and hacks for life and tech...</description>
	<lastBuildDate>Tue, 06 Jul 2010 15:21:22 +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>OOP PHP:  What is the Double Colon in Objects/Classes for?</title>
		<link>http://www.whypad.com/posts/php-using-the-double-colon/500/</link>
		<comments>http://www.whypad.com/posts/php-using-the-double-colon/500/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 21:26:03 +0000</pubDate>
		<dc:creator>Byron Bennett</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://www.whypad.com/?p=500</guid>
		<description><![CDATA[I happen to be the only PHP programmer that I know, so it&#8217;s hard to ask your buddy what the heck that :: is used for in some OO PHP programs.  I know you could post it on a forum and get the answer, but I never did.  And Google wasn&#8217;t really forth coming when [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.whypad.com/wp-content/uploads/php.gif" alt="php" title="php" width="120" height="67" class="alignleft size-full wp-image-502" />I happen to be the only PHP programmer that I know, so it&#8217;s hard to ask your buddy what the heck that :: is used for in some OO PHP programs.  I know you could post it on a forum and get the answer, but I never did.  And Google wasn&#8217;t really forth coming when you put :: in a search.  Finally I found it in the PHP documentation:  check out <a href="http://us.php.net/manual/en/language.oop5.paamayim-nekudotayim.php">Scope Resolution Operator (::)</a>.  In short, it&#8217;s used to access Static or Constant members of a class.  Here&#8217;s a brief example:</p>
<p><span id="more-500"></span></p>
<pre class="brush: php;"> class DatabaseConnector {
   const CONNECTION_STRING = 'myconnectionstring';
}

//Referece that connection string constant like so...
DatabaseConnector::CONNECTION_STRING;
</pre>
<p>So there you go, mystery solved <img src='http://www.whypad.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>In case you&#8217;re wondering what the :: is called, it&#8217;s a Paamayim Nekudotayim, which is Hebrew for the cryptic phrase: double colon!</p>
<p>Cheers,<br />
Byron</p>
<img src="http://www.whypad.com/?ak_action=api_record_view&id=500&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.whypad.com/posts/php-using-the-double-colon/500/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>PHP: Using Switch to test Multiple Conditions</title>
		<link>http://www.whypad.com/posts/php-using-switch-to-test-multiple-conditions/210/</link>
		<comments>http://www.whypad.com/posts/php-using-switch-to-test-multiple-conditions/210/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 03:41:10 +0000</pubDate>
		<dc:creator>Byron Bennett</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://www.whypad.com/?p=210</guid>
		<description><![CDATA[Ok, so maybe this is common knowledge, but I still felt a little clever when I figured out this trick.  The situation was that I wanted to test a bunch of different conditions to figure out which time category a date falls into.  It would be fairly simple to do with a bunch of if&#8230;then&#8230;else&#8217;s, [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so maybe this is common knowledge, but I still felt a little clever when I figured out this trick.  The situation was that I wanted to test a bunch of different conditions to figure out which time category a date falls into.  It would be fairly simple to do with a bunch of if&#8230;then&#8230;else&#8217;s, but really ugly.  Here&#8217;s the trick I came up with&#8230;use   switch(true), and then set up your cases to evaluate to true or false.  Here&#8217;s some example code:</p>
<p><span id="more-210"></span></p>
<pre>

$mymd = date('Ymd', $row->date_due);
$tymd = date('Ymd');  //Today

switch (true) {
	case $mymd == $tymd :
		$ind = "today";
		break;
	case $mymd < $tymd :
		$ind = "overdue";
		break;
	case $mymd < ($tymd + (6 - date('w'))) :
		$ind = "restofweek";
		break;
	default :
		$ind = (int) date('Ym',$row['duedate']);
		break;
}
</pre>
<img src="http://www.whypad.com/?ak_action=api_record_view&id=210&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.whypad.com/posts/php-using-switch-to-test-multiple-conditions/210/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Proper Case Function for PHP Strings</title>
		<link>http://www.whypad.com/posts/php-proper-case-function/201/</link>
		<comments>http://www.whypad.com/posts/php-proper-case-function/201/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 21:40:16 +0000</pubDate>
		<dc:creator>Byron Bennett</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.whypad.com/?p=201</guid>
		<description><![CDATA[Yes, PHP does have a proper case function for strings: ucwords($string) If you&#8217;re looking for the lower and upper case string functions&#8230;here you go: strtolower($string); strtoupper($string); Why not a strtoproper(), just to keep it consistent? Well, consistency here wouldn&#8217;t exactly be consistent for PHP, would it ?]]></description>
			<content:encoded><![CDATA[<p>Yes, PHP does have a proper case function for strings: ucwords($string)</p>
<p>If you&#8217;re looking for the lower and upper case string functions&#8230;here you go:</p>
<p>strtolower($string);</p>
<p>strtoupper($string);</p>
<p>Why not a strtoproper(), just to keep it consistent? Well, consistency here wouldn&#8217;t exactly be consistent for PHP, would it <img src='http://www.whypad.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ?</p>
<img src="http://www.whypad.com/?ak_action=api_record_view&id=201&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.whypad.com/posts/php-proper-case-function/201/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: What is the &amp; Ampersand Preceding Variables</title>
		<link>http://www.whypad.com/posts/php-what-is-the-ampersand-preceding-variables/193/</link>
		<comments>http://www.whypad.com/posts/php-what-is-the-ampersand-preceding-variables/193/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 05:16:32 +0000</pubDate>
		<dc:creator>Byron Bennett</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.whypad.com/?p=193</guid>
		<description><![CDATA[Well, this one is hard to find on Google, so I&#8217;m putting it in WhyPad to make it easy to find&#8230;at least for me, and I guess for you too since you here. Welcome! You may see PHP code snippets (PHP 5+ only) that have an ampersand, &#8216;&#38;&#8217;, preceding a variable like &#38;$my_variable. So, what [...]]]></description>
			<content:encoded><![CDATA[<p>Well, this one is hard to find on Google, so I&#8217;m putting it in WhyPad to make it easy to find&#8230;at least for me, and I guess for you too since you here. Welcome! You may see PHP code snippets (PHP 5+ only) that have an ampersand, &#8216;&amp;&#8217;, preceding a variable like &amp;$my_variable. So, what does it do? It sets up a reference to the original variable instead of copying it&#8217;s value. The following snippet demonstrates:<span id="more-193"></span></p>
<pre>$original = "foo";
$ref = &amp;$original;

echo $ref;   \\Prints  "foo"....Note that you don't continue to use the '&amp;' after the var is initialized

now change $original

$original = "bar";

echo $ref;  \\Now prints:  "bar"</pre>
<p>$ref would be unaffected by changes to $original if it had been set using the normal: $ref = $original;</p>
<p>Next to figure out what that @ is doing in PHP code&#8230; <img src='http://www.whypad.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><strong>[UPDATE] David sheds light on the &#8220;@&#8221; below&#8230;Thanks David!</strong></p>
<p>Cheers,<br />
Byron</p>
<img src="http://www.whypad.com/?ak_action=api_record_view&id=193&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.whypad.com/posts/php-what-is-the-ampersand-preceding-variables/193/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Codeigniter: ActiveRecord Join Tip</title>
		<link>http://www.whypad.com/posts/codeigniter-activerecord-join-tip/178/</link>
		<comments>http://www.whypad.com/posts/codeigniter-activerecord-join-tip/178/#comments</comments>
		<pubDate>Thu, 22 May 2008 05:29:35 +0000</pubDate>
		<dc:creator>Byron Bennett</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.whypad.com/?p=178</guid>
		<description><![CDATA[I ran into a problem with a SQL JOIN in Codeigniter&#8217;s ActiveRecord class. This post will help you get past that, but first a little intro to frameworks. If you&#8217;re a PHP developer, you have probably considered one of the incredibly useful frameworks that are available today. Cake, Zend, Symfony, and Codeigniter are some of [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="lightbox" href="http://www.whypad.com/wp-content/uploads/ci_flame.jpg"><img class="alignleft size-full wp-image-179" title="ci_flame" src="http://www.whypad.com/wp-content/uploads/ci_flame.jpg" alt="" width="150" height="164" /></a>I ran into a problem with a SQL JOIN in Codeigniter&#8217;s ActiveRecord class.  This post will help you get past that, but first a little intro to frameworks.  If you&#8217;re a PHP developer, you have probably considered one of the incredibly useful frameworks that are available today.  <a href="http://www.cakephp.org/">Cake</a>, <a href="http://framework.zend.com/">Zend</a>, <a href="http://www.symfony-project.org/">Symfony</a>, and <a href="http://codeigniter.com/">Codeigniter</a> are some of the biggest names in the PHP framework game today.  I&#8217;ve tried both Cake and Codeigniter, and found Codeigniter less strict, so I&#8217;ve been gravitating towards it.  If you haven&#8217;t tried a framework, I highly recommend doing so.  Any of the four I&#8217;ve listed are excellent choices, each with strengths and weaknesses, and rabid fans who can take their zealotry to extremes at times.  As with anything that requires a computer, there is always a learning curve when taking on a framework, whether it&#8217;s figuring out MVC or just learning the syntax and structure of the framework itself.  But the payoff is tremendous amounts of functionality that you don&#8217;t have to code, somewhat enforced structure, and possibly even cleaner, more manageable code.  Check out <a href="http://codeigniter.com/user_guide/">Codeigniter&#8217;s User&#8217;s Guide</a> to give you some idea of its features (you&#8217;ll have to click the little black &#8220;Table of Contents&#8221; tab at the very top &amp; right of the page&#8230;it&#8217;s sort of hidden).<span id="more-178"></span></p>
<h2>My Codeigniter SQL JOIN Problem</h2>
<p>Let me start by saying that this was my problem, not Codeigniter&#8217;s.  If only I&#8217;d read the freakin&#8217; manual a little closer.  So anyhoo, my problem was that I was trying to join 2 tables with a LEFT OUTER JOIN, but it wasn&#8217;t working.  My code was looking like:</p>
<pre>        $this-&gt;db-&gt;select('tr_dests.*', 'tr_states.state_name');
        $this-&gt;db-&gt;where('dest_id',$dest_id);
        $this-&gt;db-&gt;from('tr_dests');
	$this-&gt;db-&gt;join('tr_states','tr_dests.state = tr_states.state', 'LEFT OUTER');

        $query = $this-&gt;db-&gt;get();</pre>
<p>This was giving me the left hand table data just fine, but I was getting an empty result for my &#8220;state_name&#8221; column.  It is shameful how long I spent trying to figure out what my problem was.  Of course, I was convinced that there was something wrong with Codeigniter Activerecord class.  So, I really didn&#8217;t try everything.</p>
<h2>The Answer:</h2>
<p>The problem was in my SELECT statement.  I really thought I was ok there, but how wrong I was!    <span style="text-decoration: underline;">Only use one string of fields per line.</span> This is how you would do the SELECT:</p>
<pre>        $this-&gt;db-&gt;select('tr_dests.*, tr_states.state_name');

        or

        $this-&gt;db-&gt;select('tr_dests.*');
        $this-&gt;db-&gt;select('tr_states.state_name');

        or as Derek notes below in the comments

        $this-&gt;db-&gt;select('tr_dests.*, tr_states.state_name', FALSE);

        The FALSE argument is optional. It tells CodeIgniter not to protect the fields or table names with back slashes.  Generally, you won't need to use that.
</pre>
<p>Maybe that will save someone an hour or two&#8230;or three.  I feel stupid&#8230;lesson learned!</p>
<img src="http://www.whypad.com/?ak_action=api_record_view&id=178&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.whypad.com/posts/codeigniter-activerecord-join-tip/178/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
