<?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>Sean Gates' Blog &#187; PHP</title>
	<atom:link href="http://www.seangates.com/category/web-development/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.seangates.com</link>
	<description>By the looks of it {he thinks} he knows what he's doing.</description>
	<lastBuildDate>Sat, 10 Jul 2010 21:22:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>CodeIgniter and SSL</title>
		<link>http://www.seangates.com/2010/07/09/codeigniter-and-ssl/</link>
		<comments>http://www.seangates.com/2010/07/09/codeigniter-and-ssl/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 05:13:07 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.seangates.com/?p=91</guid>
		<description><![CDATA[I&#8217;m sure there are lots of resources for this, but here is a fairly robust one (WARNING: Don&#8217;t do what Mohammed did! I&#8217;ll tell you why in a second): http://sajjadhossain.com/2008/10/27/ssl-https-urls-and-codeigniter/ So, what&#8217;s wrong with the approach? He&#8217;s editing core files which is a big no no. He should be extending the functionality of the core [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure there are lots of resources for this, but here is a fairly robust one (WARNING: Don&#8217;t do what Mohammed did!  I&#8217;ll tell you why in a second):</p>
<p><a href="http://sajjadhossain.com/2008/10/27/ssl-https-urls-and-codeigniter/">http://sajjadhossain.com/2008/10/27/ssl-https-urls-and-codeigniter/</a></p>
<p>So, what&#8217;s wrong with the approach?  He&#8217;s <strong>editing core files</strong> which is a big no no.  He should be extending the functionality of the core files.  For example, here are the two files I now have in my site:</p>
<p><code>/application/helpers/MY_url_helper.php<br />
/application/libraries/MY_Config.php</code></p>
<p>Then, I placed the following code in each of those files, respectively:<br />
<span id="more-91"></span></p>
<h3>MY_url_helper.php</h3>
<pre class="brush: php;">&lt;?php
if( ! function_exists('secure_site_url') )
{
    function secure_site_url($uri = '')
    {
        $CI =&amp; get_instance();
        return $CI-&gt;config-&gt;secure_site_url($uri);
    }
}

if( ! function_exists('secure_base_url') )
{
    function secure_base_url()
    {
        $CI =&amp; get_instance();
        return $CI-&gt;config-&gt;slash_item('secure_base_url');
    }
}

if ( ! function_exists('secure_anchor'))
{
    function secure_anchor($uri = '', $title = '', $attributes = '')
    {
        $title = (string) $title;

        if ( ! is_array($uri))
        {
            $secure_site_url = ( ! preg_match('!^\w+://! i', $uri)) ? secure_site_url($uri) : $uri;
        }
        else
        {
            $secure_site_url = secure_site_url($uri);
        }

        if ($title == '')
        {
            $title = $secure_site_url;
        }

        if ($attributes != '')
        {
            $attributes = _parse_attributes($attributes);
        }

        return '&lt;a href=&quot;'.$secure_site_url.'&quot;&gt;'.$title.'&lt;/a&gt;';
    }
}

if ( ! function_exists('secure_redirect'))
{
    function secure_redirect($uri = '', $method = 'location', $http_response_code = 302)
    {
        switch($method)
        {
            case 'refresh'    : header(&quot;Refresh:0;url=&quot;.secure_site_url($uri));
                break;
            default            : header(&quot;Location: &quot;.secure_site_url($uri), TRUE, $http_response_code);
                break;
        }
        exit;
    }
}

if (! function_exists('force_ssl'))
{
    function force_ssl()
    {
        if ($_SERVER[&quot;SERVER_PORT&quot;] != 443)
        {
            redirect(str_replace(&quot;http://&quot;, &quot;https://&quot; , current_url()), &quot;refresh&quot;);
        }
    }
}</pre>
<h3>MY_Config.php</h3>
<pre class="brush: php;">&lt;?php
class MY_Config extends CI_Config {

	function MY_Config()
	{
		parent::CI_Config();
	}

	function secure_site_url($uri = '')
	{
	    if (is_array($uri))
	    {
	        $uri = implode('/', $uri);
	    }

	    if ($uri == '')
	    {
	        return $this-&gt;slash_item('secure_base_url').$this-&gt;item('index_page');
	    }
	    else
	    {
	        $suffix = ($this-&gt;item('url_suffix') == FALSE) ? '' : $this-&gt;item('url_suffix');
	       return $this-&gt;slash_item('secure_base_url').$this-&gt;slash_item('index_page').preg_replace(&quot;|^/*(.+?)/*$|&quot;, &quot;\\1&quot;, $uri).$suffix;
	    }
	}
}</pre>
<p>Now, that was easy, wasn&#8217;t it?  Go forth and do awesome stuff with this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seangates.com/2010/07/09/codeigniter-and-ssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Related Bridge in EE</title>
		<link>http://www.seangates.com/2008/05/01/related-bridge-in-ee/</link>
		<comments>http://www.seangates.com/2008/05/01/related-bridge-in-ee/#comments</comments>
		<pubDate>Thu, 01 May 2008 21:49:27 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Expression Engine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.seangates.com/2008/05/01/related-bridge-in-ee/</guid>
		<description><![CDATA[I&#8217;ve been using Expression Engine for a couple of weeks now, mostly for work projects. It&#8217;s been good to see how a group of people have thought of abstracting data for almost any application. It will be interesting to see if it can solve many of the problems I&#8217;ve run into when developing extremely custom [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Expression Engine for a couple of weeks now, mostly for work projects.  It&#8217;s been good to see how a group of people have thought of abstracting data for almost any application.  It will be interesting to see if it can solve many of the problems I&#8217;ve run into when developing extremely custom applications.</p>
<p>So, one problem that we&#8217;ve come across is a way to relate several tables (or weblogs as EE calls them) together.  An example would be like so:  doctors, their specialties, and the locations of their practice.  A likely scenario is a user wants to find out what locations provide a certain specialty.  Thus, you have to use the doctors as the bridge of the data.</p>
<p>In Expression Engine you can use a related field to tie two tables of data together.  For instance, I can tie a Doctor to a certain specialty using a related field.  But, creating a bridge between the doctors&#8217; specialties and all the locations is not possible without a little custom programming.</p>
<p>Also, throw in the mix that doctors can have offices at several locations, and you&#8217;ve got a hairy set of data. (We&#8217;re using the multi-relationship plug-in from <a href="http://expressionengine.com/forums/viewthread/39595/">here</a>).<br />
<span id="more-57"></span><br />
So, let&#8217;s get to the code.</p>
<pre class="brush: php;">&lt;?php
global $DB;
$addresses = $DB-&gt;query(&quot;SELECT * FROM `exp_weblog_data` WHERE weblog_id = 6&quot;);
foreach($addresses-&gt;result as $address){
	$doctors = $DB-&gt;query(&quot;SELECT * FROM `exp_weblog_data` WHERE weblog_id = 3&quot;);
	foreach($doctors-&gt;result as $doc){
		$rel_field_ids = array(2);
		$rel_field_ids_new = '';
		$rel_field_ids[0] = $doc['field_id_34'];
		$rel_field_ids[1] = ereg_replace(&quot;\r&quot;,&quot;,&quot;,$doc['field_id_35']);
		$rel_field_ids_new = &quot;'&quot; . implode(&quot;','&quot;,$rel_field_ids) . &quot;'&quot;;
		$specialties = $DB-&gt;query(&quot;SELECT * FROM exp_relationships WHERE rel_id IN (&quot; . $rel_field_ids_new . &quot;)&quot;);
		foreach($specialties-&gt;result as $specialty){
			if($specialty['rel_child_id'] == $address['entry_id']){
				$specs[] = $specialty['rel_parent_id'];
			}
		}
	}

	if(sizeof($specs) &gt; 0) {
		$specialties_ids = $DB-&gt;query(&quot;SELECT field_id_13 FROM exp_weblog_data WHERE entry_id IN(&quot; . implode($specs,',') . &quot;)&quot;);
		foreach($specialties_ids-&gt;result as $s_id){
			$related_spec = $DB-&gt;query(&quot;SELECT * FROM exp_relationships WHERE rel_id = &quot; . $s_id['field_id_13']);
			$related_spec_title = $DB-&gt;query(&quot;SELECT title FROM exp_weblog_titles WHERE entry_id = &quot; . $related_spec-&gt;row['rel_child_id']);
			if(!in_array($related_spec_title-&gt;row['title'],$titles_array)){ $titles_array[] = $related_spec_title-&gt;row['title']; }
		}
	}
	implode($titles_array,&quot;','&quot;)
}
?&gt;</pre>
<p>So, in a nutshell the code above will compare the locations with the specialties using the exp_relationships table and the doctor as the bridge.</p>
<p>I had to think about it a bit, but you kinda get the idea.  I hope this helps someone out there struggling with the same issue.</p>
<p>Happy coding.</p>
<p><strong>Note:</strong> When copying this code make sure you replace the curly quotes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seangates.com/2008/05/01/related-bridge-in-ee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coldfusion and bad-for-you-coffee</title>
		<link>http://www.seangates.com/2008/04/15/coldfusion-and-bad-for-you-coffee/</link>
		<comments>http://www.seangates.com/2008/04/15/coldfusion-and-bad-for-you-coffee/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 14:54:25 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.seangates.com/2008/04/15/coldfusion-and-bad-for-you-coffee/</guid>
		<description><![CDATA[I was a bit surprised when I came across this post today, and so frustrated by it that I had to write about it. Read it here: JeremiahX on Coldfusion In a nutshell, J. J. speaks of his affinity for ColdFusion, and how it is like the best-tasting coffee that everyone loves to hate. I [...]]]></description>
			<content:encoded><![CDATA[<p>I was a bit surprised when I came across this post today, and so frustrated by it that I had to write about it.</p>
<p>Read it here: <a href="http://jeremiahx.com/2008/04/11/coldfusion-is-to-programming-as-starbucks-is-to-coffee/">JeremiahX on Coldfusion</a></p>
<p>In a nutshell, J. J. speaks of his affinity for ColdFusion, and how it is like the best-tasting coffee that everyone loves to hate.  I would liken that to the best operating system everyone loves to hate, Windows &#8230; if you catch my drift.  Those of you that know me know that I am platform agnostic, language agnostic, and altogether technology agnostic.  I&#8217;ve worked in almost every web development environment and have solid web development chops to be able to speak about what works and what doesn&#8217;t.</p>
<p>ColdFusion doesn&#8217;t work.</p>
<p>Granted, I haven&#8217;t been so incredibly deep in the trenches that I understand all of it&#8217;s nuances, standards, techniques.  But, who does?  What I&#8217;m getting at here is that programming is an imaginative thing most of the time.  And with ColdFusion I don&#8217;t feel I can imagine very far.  There&#8217;s really only so much you can do with it.</p>
<p>Also, Adobe has continued to shuffle their feet in developing anything new for ColdFusion, and they are really behind the curve.  From a business perspective, companies who utilize ColdFusion in their software development will continue to use it, but they will always be fixing problems other languages have fixed years ago.</p>
<p>PHP, on the other hand, is used much more widely that ColdFusion, and for good reason.  It&#8217;s adoption points to the fact that it has a very small learning curve, has mounds and mounds of support on the Internet, is FREE, is platform independent, and has blazingly fast compilation.  And, PHP is as up-to-date as it comes to supporting the newest web technologies and making it easy to develop with.  Oh, and did I mention it&#8217;s FREE?</p>
<p>And coffee is bad for you, too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seangates.com/2008/04/15/coldfusion-and-bad-for-you-coffee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Columns in Select Boxes</title>
		<link>http://www.seangates.com/2007/03/23/columns-in-select-boxes/</link>
		<comments>http://www.seangates.com/2007/03/23/columns-in-select-boxes/#comments</comments>
		<pubDate>Fri, 23 Mar 2007 20:17:44 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.seangates.com/?p=36</guid>
		<description><![CDATA[I came across a problem yesterday where I needed to create columns in select boxes. My issue revolved around showing an ID in the left column, and a description of the ID in the right column. This is due to the fact that people in our organization know most things by their ID, but my [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a problem yesterday where I needed to create columns in select boxes.  My issue revolved around showing an ID in the left column, and a description of the ID in the right column.  This is due to the fact that people in our organization know most things by their ID, but my not know how to distinguish between similar IDs.  The ids are alphanumeric.  For example: SYS2007.  This could mean &#8220;System 2007&#8243;.  Then there could be one called SYS2007B.  Similar, but different.</p>
<p>So, I searched the web and found nothing about doing it in HTML or CSS (I figured as much but gave it a shot anyway).  Then I came up with this idea: use a fixed width font and fill in missing spaces.  So, I made the select box use courier.</p>
<pre>&lt;select ... style="font-family: courier;"&gt;</pre>
<p>Then I set about populating the box (using PHP of course) and came up with a small tidbit to fill in the extra spaces:</p>
<pre>formatID($id){</pre>
<pre>$str_length = strlen($id);</pre>
<pre>for($i=0; $i&lt;(15-$str_length); $i++){</pre>
<pre>$add_spaces = $add_spaces . ' ';</pre>
<pre>}</pre>
<pre>return $id . $add_spaces;</pre>
<pre>}</pre>
<p>Now, I use the function when looping through and building the select box:</p>
<pre>foreach($ps as $p){</pre>
<pre>echo '&lt;option id="' . $p-&gt;ID . '"</pre>
<pre>value="' . $p-&gt;ID . '"&gt;' .</pre>
<pre>formatSCN($p-&gt;ID) . $p-&gt;Title .</pre>
<pre>'&lt;/option&gt;';</pre>
<pre>}</pre>
<p>So, now what comes out is a column at the front that is formatted with a fixed width of characters.  Now you could do this if you wanted to format any number of columns, and not just the first. It may be cool if this showed 5 or 10+ columns of data.  But, that may be a usability issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seangates.com/2007/03/23/columns-in-select-boxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regex Love</title>
		<link>http://www.seangates.com/2007/03/19/33/</link>
		<comments>http://www.seangates.com/2007/03/19/33/#comments</comments>
		<pubDate>Mon, 19 Mar 2007 18:05:32 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Javscript]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.seangates.com/?p=33</guid>
		<description><![CDATA[I have been doing some regular expression work in JavaScript the past couple of days, and I realize regular expressions can be powerful and do a lot for me. The following examples are variations (not the actual because I could get in trouble here at work) of what I was able to do off the [...]]]></description>
			<content:encoded><![CDATA[<p>I have been doing some regular expression work in JavaScript the past couple of days, and I realize regular expressions can be powerful and do a lot for me.  The following examples are variations (not the actual because I could get in trouble here at work) of what I was able to do off the top of my head:</p>
<blockquote><p>/^p\d{3}$/     // looks for a &#8220;p&#8221; followed by 3 digits<br />
/^\d{6}(-\d{6})?$/     // looks for 6 digits with an optional dash then 6 more digits</p></blockquote>
<p>Just thought I&#8217;d share in my own joy.  Can you see the joy in those regex?  Love it.</p>
<blockquote><p>Note: I fixed the second example per Mitch&#8217;s bug find.Ã‚Â  Apparently my transcription from my whiteboard was not perfect. :-)</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.seangates.com/2007/03/19/33/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sorting Associative Arrays in PHP</title>
		<link>http://www.seangates.com/2006/07/26/sorting-associative-arrays-in-php/</link>
		<comments>http://www.seangates.com/2006/07/26/sorting-associative-arrays-in-php/#comments</comments>
		<pubDate>Wed, 26 Jul 2006 18:10:00 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.orwd.com/blog/?p=16</guid>
		<description><![CDATA[IÃ‚Â encountered a problem yesterday (that flowed into today)Ã‚Â dealing with associative arrays and how to sort them.Ã‚Â My problem was that I had to merge two associative arrays, then sort them based on a value in the second level array. Here is an example: $my_array1 = array( Ã‚Â Ã‚Â Ã‚Â Ã‚Â array( Ã‚Â Ã‚Â [...]]]></description>
			<content:encoded><![CDATA[<p>IÃ‚Â encountered a problem yesterday (that flowed into today)Ã‚Â dealing with associative arrays and how to sort them.Ã‚Â  My problem was that I had to merge two associative arrays, then sort them based on a value in the second level array.<span id="more-16"></span></p>
<p>Here is an example:</p>
<blockquote><p><font face="Courier New">$my_array1 = array(<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â  array(<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â  &#8216;id&#8217; => &#8217;1&#8242;,<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â  &#8216;name&#8217; => &#8216;tom&#8217;<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â  ),<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â  array(<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â  &#8216;id&#8217; => &#8217;2&#8242;,<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â  &#8216;name&#8217; => &#8216;harry&#8217;<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â  )<br />
);<br />
</font><font face="Courier New">$my_array2 = array(<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â  array(<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â  &#8216;id&#8217; => &#8217;5&#8242;,<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â  &#8216;name&#8217; => &#8216;dick&#8217;<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â  ),<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â  array(<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â  &#8216;id&#8217; => &#8217;4&#8242;,<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â Ã‚Â  &#8216;name&#8217; => &#8216;bob&#8217;<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â  )<br />
);<br />
</font><font face="Courier New">$merged_array = array_merge( $my_array1 , $my_array2 );</font></p></blockquote>
<p>Now, this part worked fine and dandy, except when I went to sort the merged array.Ã‚Â  I was using usort and a function I had found on the internet:</p>
<blockquote><p><font face="Courier New"><span class="keyword">function </span><span class="default">arfsort</span><span class="keyword">( </span><span class="default">$a</span><span class="keyword">, </span><span class="default">$fl </span></font><font face="Courier New"><span class="keyword">){<br />
Ã‚Â  </span><span class="default">$GLOBALS</span><span class="keyword">[</span><span class="string">'__ARFSORT_LIST__'</span><span class="keyword">] = </span><span class="default">$fl</span></font><font face="Courier New"><span class="keyword">;<br />
Ã‚Â  </span><span class="default">usort</span><span class="keyword">( </span><span class="default">$a</span><span class="keyword">, </span><span class="string">&#8216;arfsort_func&#8217; </span></font><font face="Courier New"><span class="keyword">);<br />
Ã‚Â  return </span><span class="default">$a</span></font><span class="keyword"><font face="Courier New">;<br />
}</font></span><span class="keyword"><font face="Courier New"><font face="Courier New"><span class="comment">// extended to allow sort direction per field sorted against<br />
</span><span class="keyword">function </span><span class="default">arfsort_func</span><span class="keyword">( </span><span class="default">$a</span><span class="keyword">, </span><span class="default">$b </span></font><font face="Courier New"><span class="keyword">){<br />
Ã‚Â  foreach( </span><span class="default">$GLOBALS</span><span class="keyword">[</span><span class="string">'__ARFSORT_LIST__'</span><span class="keyword">] as </span><span class="default">$f </span></font><font face="Courier New"><span class="keyword">) {<br />
Ã‚Â Ã‚Â  switch (</span><span class="default">$f</span><span class="keyword">[</span><span class="default">1</span><span class="keyword">]) { </span></font><font face="Courier New"><span class="comment">// switch on ascending or descending value<br />
Ã‚Â Ã‚Â  Ã‚Â  </span><span class="keyword">case </span><span class="string">&#8220;d&#8221;</span></font><font face="Courier New"><span class="keyword">:<br />
Ã‚Â Ã‚Â  Ã‚Â  Ã‚Â  </span><span class="default">$strc </span><span class="keyword">= </span><span class="default">strcmp</span><span class="keyword">( </span><span class="default">strtolower</span><span class="keyword">(</span><span class="default">$b</span><span class="keyword">[</span><span class="default">$f</span><span class="keyword">[</span><span class="default">0</span><span class="keyword">]]), </span><span class="default">strtolower</span><span class="keyword">(</span><span class="default">$a</span><span class="keyword">[</span><span class="default">$f</span><span class="keyword">[</span><span class="default">0</span></font><font face="Courier New"><span class="keyword">]]) );<br />
Ã‚Â Ã‚Â  Ã‚Â  Ã‚Â  if ( </span><span class="default">$strc </span><span class="keyword">!= </span><span class="default">0 </span></font><font face="Courier New"><span class="keyword">){<br />
Ã‚Â Ã‚Â  Ã‚Â  Ã‚Â  Ã‚Â  return </span><span class="default">$strc</span></font><font face="Courier New"><span class="keyword">;<br />
Ã‚Â Ã‚Â  Ã‚Â  Ã‚Â  }<br />
Ã‚Â Ã‚Â  Ã‚Â  break;<br />
Ã‚Â Ã‚Â  Ã‚Â  default:<br />
Ã‚Â Ã‚Â  Ã‚Â  Ã‚Â  </span><span class="default">$strc </span><span class="keyword">= </span><span class="default">strcmp</span><span class="keyword">( </span><span class="default">strtolower</span><span class="keyword">(</span><span class="default">$a</span><span class="keyword">[</span><span class="default">$f</span><span class="keyword">[</span><span class="default">0</span><span class="keyword">]]), </span><span class="default">strtolower</span><span class="keyword">(</span><span class="default">$b</span><span class="keyword">[</span><span class="default">$f</span><span class="keyword">[</span><span class="default">0</span></font><font face="Courier New"><span class="keyword">]]) );<br />
Ã‚Â Ã‚Â  Ã‚Â  Ã‚Â  if ( </span><span class="default">$strc </span><span class="keyword">!= </span><span class="default">0 </span></font><font face="Courier New"><span class="keyword">){<br />
Ã‚Â Ã‚Â  Ã‚Â  Ã‚Â  Ã‚Â  return </span><span class="default">$strc</span></font><font face="Courier New"><span class="keyword">;<br />
Ã‚Â Ã‚Â  Ã‚Â  Ã‚Â  }<br />
Ã‚Â Ã‚Â  Ã‚Â  break;<br />
Ã‚Â Ã‚Â  }<br />
Ã‚Â  }<br />
Ã‚Â  return </span><span class="default">0</span></font><span class="keyword"><font face="Courier New">;<br />
}</font></span></font></span></p></blockquote>
<p>What was happening was that the usort was not working.Ã‚Â  So, I started to think about ways to get around the problem of the usort.Ã‚Â  My first thoughts were some way to work around it in PHP, so I went and asked a colleague if she new of any way to sort associative arrays in the fashion I needed to.Ã‚Â  Her first comment was to try and do something in the SQL query before you ever get the data.Ã‚Â  We talked for a bit and I got this bright idea.Ã‚Â  I could use the handy IN operator from MySQL.Ã‚Â  First, I would have to build a string of IDs for the database, then use the IN operator to query for just those IDs in the database.Ã‚Â  For example:</p>
<blockquote><p><font face="Courier New">$my_array1 &#8230;. (like above)<br />
$my_array2 &#8230;. (like above)</font></p>
<p><font face="Courier New">$merged_array = array_merge( $my_array1 , $my_array2 );</font></p>
<p><font face="Courier New">foreach($merged_array as $m){<br />
Ã‚Â Ã‚Â Ã‚Â Ã‚Â  $merge_list[] = $m['id'];<br />
}</font></p>
<p><font face="Courier New">$list_for_query = implode(&#8216;,&#8217;,$merge_list);</font></p>
<p><font face="Courier New">$query = &#8220;SELECT * FROM my_table WHERE id IN ($merge_list) ORDER BY name&#8221;;</font></p></blockquote>
<p>So, to explain the above code it goes something like this:</p>
<ol>
<li>Make the arrays (mine were two different queries that I needed to merge together)</li>
<ul>
<li>Note: the arrays just need to have the row ID in them.Ã‚Â  No sense in wasting time getting all the columns from the table</li>
</ul>
<li>Merge the arrays (they need to be identical)</li>
<li>Make the associative arrays a one level array</li>
<li>Implode the list so there are commas separating the ID values</li>
<li>Query using those ID values and use ORDER BY to get the correct sorting</li>
</ol>
<p>Lo and behold, it works.Ã‚Â  It does just what I want, and I don&#8217;t have to fuss about using a custom usort.Ã‚Â  Hopefully this will help someone else down the road so you don&#8217;t waste your time like I did.</p>
<p>Ã‚Å </p>
]]></content:encoded>
			<wfw:commentRss>http://www.seangates.com/2006/07/26/sorting-associative-arrays-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Command Line Scripting With MSSQL</title>
		<link>http://www.seangates.com/2006/04/10/php-command-line-scripting-with-mssql/</link>
		<comments>http://www.seangates.com/2006/04/10/php-command-line-scripting-with-mssql/#comments</comments>
		<pubDate>Mon, 10 Apr 2006 21:49:55 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.orwd.com/blog/?p=14</guid>
		<description><![CDATA[What an ordeal.Ã‚Â 5 days and many, many hours, and I still was in a quandry until this morning. Here is the long story: Here at work (ADP Dealer Services) I have developed a website for documentation writers to publish their documents for review.Ã‚Â It allows them to send out emails whenÃ‚Â everything is published, [...]]]></description>
			<content:encoded><![CDATA[<p>What an ordeal.Ã‚Â  5 days and many, many hours, and I still was in a quandry until this morning.<span id="more-14"></span></p>
<p>Here is the long story:</p>
<p>Here at work (<a href="http://www.dealersuite.com" target="_blank">ADP Dealer Services</a>) I have developed a website for documentation writers to publish their documents for review.Ã‚Â  It allows them to send out emails whenÃ‚Â everything is published, notifying the reviewers that they need to take action.Ã‚Â  As part of this website I have built a PHP script that will send out notifications when the review is 3 days from closing.Ã‚Â  I need to have this script run every morning at 5 a.m.</p>
<p>Because I was using Windows XP as the server host, I was able to use Windows Task Scheduler to run the command line PHP command at the specified interval (every morning 5 a.m.).Ã‚Â  This works fine.</p>
<p>My automated script connects to two different databases, one is MySQL that holds the review, reviewer and requestorÃ‚Â data, and the other isÃ‚Â MSSQL which holds the reviewer email addresses.Ã‚Â  When I run the script from the browser all is fine, but as soon as I run it from the command line via php.exe it dies:</p>
<blockquote><p>C:>C:\wamp\php\php.exe C:\wamp\www\pathtoscript\auto.php</p></blockquote>
<p>I was able to track down the problem in the mssql_connect() function.Ã‚Â  This let me on a wild goose chase for the solution.Ã‚Â  I looked at installing the MSSQL server client toolsÃ‚Â and also atÃ‚Â creating a direct link to theÃ‚Â MSSQL driverÃ‚Â with the dl() function.Ã‚Â  Those were the two most promising solutions, but neither fully fixed the issue.</p>
<p>I realized today that there was probably no way to get the CLI implementation workingÃ‚Â using the mssql_connect() function, so I tried to brainstorm a way to connect to the MSSQL Server.Ã‚Â  Then it hit me.Ã‚Â  I could use <a href="http://www.php.net/odbc" target="_blank">ODBC</a> because I was running Windows XP.Ã‚Â  I could create a DSN that had the server connection information in it, then use that as the bridge to the MSSQL Server.</p>
<p>Needless to say, it worked.Ã‚Â  I am now able to connect to the MSSQL server using PHP&#8217;s CLI.Ã‚Â  Granted, I had to rewrite about 10 lines of code, and use a <a href="http://www.russprince.com/odbc_functions.zip" target="_blank">different database object class</a>.Ã‚Â  But, the fact remains that there is a problem usingÃ‚Â MSSQL Server functions when running PHP from the command line.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seangates.com/2006/04/10/php-command-line-scripting-with-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
