<?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>Beginnercode.com &#187; Computing</title>
	<atom:link href="http://www.beginnercode.com/category/computing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.beginnercode.com</link>
	<description>The adventures of an amateur coder</description>
	<lastBuildDate>Wed, 27 Apr 2011 20:07:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
  <link>http://www.beginnercode.com</link>
  <url>http://www.beginnercode.com/wp-content/themes/neuron/favicon.ico</url>
  <title>Beginnercode.com</title>
</image>
		<item>
		<title>Adding a second argument to CI form_validation callbacks</title>
		<link>http://www.beginnercode.com/2011/04/27/adding-a-second-argument-to-ci-form_validation-callbacks/</link>
		<comments>http://www.beginnercode.com/2011/04/27/adding-a-second-argument-to-ci-form_validation-callbacks/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 20:07:54 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=333</guid>
		<description><![CDATA[About a month ago I started working with the CodeIgniter framework. It&#8217;s the first framework I have worked with and frankly, I love it!
So I was looking to add a second parameter to a form_validation callback. Here&#8217;s what I found:

$this-&#62;form_validation('user_name', 'name', &#34;callback_test_name[$param2]&#34;);

and the callback:

test_name($name, $param2){
    ..// some logic to return
}

The form_validation class [...]]]></description>
			<content:encoded><![CDATA[<p>About a month ago I started working with the CodeIgniter framework. It&#8217;s the first framework I have worked with and frankly, I love it!</p>
<p>So I was looking to add a second parameter to a form_validation callback. Here&#8217;s what I found:</p>
<pre class="brush: php;">
$this-&gt;form_validation('user_name', 'name', &quot;callback_test_name[$param2]&quot;);
</pre>
<p>and the callback:</p>
<pre class="brush: php;">
test_name($name, $param2){
    ..// some logic to return
}
</pre>
<p>The form_validation class uses the form value as the first parameter, and you can pass the second parameter in the arguments as you would with any other rule references. (First snippet)</p>
<p>At first I was calling 2 validations. First the standard type of validation, <strong>then another validation on the same input</strong>. * BAD IDEA * </p>
<p>There were some issues with order of operations. I found it best to chain the whole lot together. Like so:</p>
<pre class="brush: php;">
$this-&gt;form_validation('user_name', 'name', &quot;required|min_length[10]|callback_test_name[$param2]&quot;);
</pre>
<p>I hope that helps anybody with the same question.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2011/04/27/adding-a-second-argument-to-ci-form_validation-callbacks/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>REGEX For common courier tracking numbers</title>
		<link>http://www.beginnercode.com/2010/11/09/regex-for-common-courier-tracking-numbers/</link>
		<comments>http://www.beginnercode.com/2010/11/09/regex-for-common-courier-tracking-numbers/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 22:37:40 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=322</guid>
		<description><![CDATA[I was on the hunt not only to find the different variations each courier had for their tracking numbers but also a regex to match. Most of the google fu I found was outdated. Fedex &#8220;recently&#8221; (months? years? days?) changed from a 12 digit to 15 digit system. And NO, tracking numbers are not totally [...]]]></description>
			<content:encoded><![CDATA[<p>I was on the hunt not only to find the different variations each courier had for their tracking numbers but also a regex to match. Most of the google fu I found was outdated. Fedex &#8220;recently&#8221; (months? years? days?) changed from a 12 digit to 15 digit system. And NO, tracking numbers are not totally random. There is usually a space separation on the printed labels you see. Each of the spaced out subsets have a meaning to the courier as well as a checksum. Checksum being, a pre selected sequence of particular number positions added together then divided by a pre selected number. That you can search up yourself if you like. I didn&#8217;t find all too much on that matter either.</p>
<p>I am not very good with regex so if there are any suggestions by l33t coderz, they are more than welcome. On with the codes:</p>
<pre class="brush: php;">

/****
[ UPS ]
9 digits, or 1Z+whatever digits
The quick brown fox 1Z9999W99999999999 jumps over the lazy dog.
*/
$ups = '/(\b\d{9}\b)|(\b1Z\d+\b)/';

/****
[ Fedex ]
12 digits, 15 digits, or '96'+ 20 digits
The quick brown fox 999999999999 jumps over the lazy dog.
*/
$fedex = '/(\b96\d{20}\b)|(\b\d{15}\b)|(\b\d{12}\b)/';

/***
[ USPS ]
30 digits, '91'+20 digits, 20 digits (untested)
&lt; TOTALLY UNTESTED BY ME AT THIS TIME &gt;
*/
$usps = '/(\b\d{30}\b)|(\b91\d+\b)|(\b\d{20}\b)/';
</pre>
<p>I did get the common characters per courier from <a href="http://www.packagetrackr.com/help/carriers">Packagetrackr</a>. I don&#8217;t know how much of it is accurate, but from what I could tell from my experience with FedEx and UPS it seemed to be in line. I was unable to find an all inclusive source.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2010/11/09/regex-for-common-courier-tracking-numbers/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using ui autocomplete as a dropdown, with type in</title>
		<link>http://www.beginnercode.com/2010/04/01/using-ui-autocomplete-as-a-dropdown-with-type-in/</link>
		<comments>http://www.beginnercode.com/2010/04/01/using-ui-autocomplete-as-a-dropdown-with-type-in/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 15:25:46 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=298</guid>
		<description><![CDATA[I had been using an autocomplete plugin by bassistance. 2 months later jQuery UI added autocomplete to their list of widgets. Like many plugins out there I was unable to find an autocomplete that was easy to use for my purposes. The closest I recently came to was the sexy combo plugin. I cant remember [...]]]></description>
			<content:encoded><![CDATA[<p>I had been using an autocomplete plugin by <a href="http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/">bassistance</a>. 2 months later jQuery UI added autocomplete to their list of widgets. Like many plugins out there I was unable to find an autocomplete that was easy to use for my purposes. The closest I recently came to was the <a href="http://code.google.com/p/sexy-combo/">sexy combo plugin</a>. I cant remember why but it was just a tad short of what I wanted to do, and I&#8217;m still quite a javascript novice.</p>
<p>I came up with a way to use the jQuery UI autocomplete widget as a &lt;select&gt; that you could also type in something if the choices in the dropdown didn&#8217;t fit your needs.</p>
<p><img src="http://www.beginnercode.com/wp-content/imgupload/2010/04/ui-autocomplete-dropdown.jpg" alt="ui-autocomplete-dropdown" title="ui-autocomplete-dropdown" width="431" height="229" class="aligncenter size-full wp-image-304" /></p>
<p>This example uses a local data source, but you can come up with creative ways to use remote JSON sources if you like.</p>
<div style="margin:10px 0 20px 0;text-align:center;"><a href="http://www.library.beginnercode.com/jQuery/ui/autocomplete.php" target="_blank">Click here for the demo</a></div>
<pre class="brush: php;">
&lt;script type=&quot;text/javascript&quot;&gt;
	$(document).ready(function() {

		// dropdown/ auto suggest
		$(&quot;.ui_dropdown&quot;).autocomplete({
			minLength: 0,
			delay: 0
		});

		$(&quot;.ui_dropdown&quot;).click(function(){

			var input = $(this);
			var inputID = input.attr('id');

			// close if already visible
			if (input.autocomplete(&quot;widget&quot;).is(&quot;:visible&quot;)) {
				input.autocomplete(&quot;close&quot;);
				return false;
			}

			// set source(s)
			var myData = '';
			if(inputID == 'input1'){
				myData = [&quot;foo&quot;,&quot;bar&quot;,&quot;hello&quot;,&quot;world&quot;];
			} else {
				myData = [&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;];
			}

			// load source
			input.autocomplete({
				source: myData
			});

			// fire search event
			input.autocomplete(&quot;search&quot;, &quot;&quot;);
			input.focus();
			return false;
		});		

	});
&lt;/script&gt;
</pre>
<p>In this script I am using the input id&#8217;s to define the data source.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2010/04/01/using-ui-autocomplete-as-a-dropdown-with-type-in/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Cloning table rows and jQuery UI Datepicker()</title>
		<link>http://www.beginnercode.com/2009/12/17/cloning-table-rows-and-jquery-ui-datepicker/</link>
		<comments>http://www.beginnercode.com/2009/12/17/cloning-table-rows-and-jquery-ui-datepicker/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 18:22:49 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=254</guid>
		<description><![CDATA[I&#8217;m rather new to both javascript and jQuery. I ran into an issue while cloning table rows that had inputs, and jQuery UI datepicker.
The cloned datepicker input would insert the picked date into the original inputs rather than the cloned row.

The inputs in my table rows had no ID&#8217;s. So what I found was either [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m rather new to both javascript and jQuery. I ran into an issue while cloning table rows that had inputs, and jQuery UI datepicker.</p>
<p>The cloned datepicker input would insert the picked date into the original inputs rather than the cloned row.<br />
<img src="http://www.beginnercode.com/wp-content/imgupload/2009/12/cloneDatepicker.jpg" alt="cloneDatepicker" title="cloneDatepicker" width="379" height="302" class="aligncenter size-full wp-image-276" /></p>
<p>The inputs in my table rows had no ID&#8217;s. So what I found was either jQuery or UI was dynamically creating it&#8217;s own DOM id&#8217;s for the inputs in the table rows that had the datepicker call. Datepicker also was dynamically inserting a class &#8220;hasDatepicker&#8221; into the inputs that had the datepicker call.</p>
<p>I resolved this by:<br />
1. Looping through the cloned rows inputs looking for any inputs with the class &#8220;hasDatepicker&#8221;.<br />
2. Removing the hasDatepicker class from any inputs with that class.<br />
3. Getting that inputs current id, incrementing it by 1, and reassigning it.<br />
4. Re-initializing the datepicker call.</p>
<div style="margin:10px 0 20px 0;text-align:center;"><a href="http://www.library.beginnercode.com/jQuery/inputs_on_the_fly/cloneDatepicker.php" target="_blank">Click here for the demo</a></div>
<pre class="brush: php;">
&lt;script type=&quot;text/javascript&quot;&gt;

$(document).ready(function(){

  // -- Clone table rows
  $(&quot;.cloneTableRows&quot;).live('click', function(){
    // do the cloning...

    // new rows datepicker need to be re-initialized
    $(newRow).find(&quot;input&quot;).each(function(){

      // if the current input has the hasDatpicker class
      if($(this).hasClass(&quot;hasDatepicker&quot;)){
        var this_id = $(this).attr(&quot;id&quot;); // current inputs id
        var new_id = this_id +1; // a new id
        $(this).attr(&quot;id&quot;, new_id); // change to new id
        $(this).removeClass('hasDatepicker'); // remove hasDatepicker class
        $(this).datepicker(); // re-init datepicker
      }

    });

  });

});

&lt;/script&gt;
</pre>
<p>Whats really neat about this particular js, is that you can call it from any table that has an id.</p>
<p><b>The only thing I have yet to figure out is how to reset the cloned datepicker to use the default class called date format. </b></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2009/12/17/cloning-table-rows-and-jquery-ui-datepicker/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Free DVD Software through October 31</title>
		<link>http://www.beginnercode.com/2009/10/20/free-dvd-software-through-october-31/</link>
		<comments>http://www.beginnercode.com/2009/10/20/free-dvd-software-through-october-31/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 21:17:38 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=236</guid>
		<description><![CDATA[winxdvd.com is giving away DVD Authoring, and DVD ripping software between now and October 31, 2009.
I downloaded and installed as soon as darkmoon told me about it. Thanks for the tip. They installed smoothly on my system, and at the price of FREE you can&#8217;t go wrong. Go grab your copies!
DVD Authoring: here 
DVD Ripping/ [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.beginnercode.com/wp-content/imgupload/2009/10/ripper.jpg" alt="ripper" title="ripper" width="150" height="187" class="alignleft size-full wp-image-238"  style="float:left;" />winxdvd.com is giving away DVD Authoring, and DVD ripping software between now and October 31, 2009.</p>
<p>I downloaded and installed as soon as <a href="http://life.firelace.com/">darkmoon</a> told me about it. Thanks for the tip. They installed smoothly on my system, and at the price of FREE you can&#8217;t go wrong. Go grab your copies!</p>
<p>DVD Authoring:<a href="http://www.winxdvd.com/specialoffer/oct09.htm"> here </a><br />
DVD Ripping/ Converting: <a href="http://www.winxdvd.com/specialoffer/sep0902.htm"> here </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2009/10/20/free-dvd-software-through-october-31/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Backup your Notepad++ FTP items</title>
		<link>http://www.beginnercode.com/2009/08/04/backup-your-notepad-ftp-items/</link>
		<comments>http://www.beginnercode.com/2009/08/04/backup-your-notepad-ftp-items/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 15:02:08 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=202</guid>
		<description><![CDATA[So in addition to reformatting friends and relatives computers, about every 2 years I clean out my own. Each time I have, I&#8217;ve lost my Notepad++ FTP synchronize settings.
In Vista they can be found in:
C:\Users\AppData\Roaming\Notepad++\plugins\config\FTP_synchronize.ini

Copy them to backup and replace. In case an update gets hosed, or you are re-installing.
]]></description>
			<content:encoded><![CDATA[<p>So in addition to reformatting friends and relatives computers, about every 2 years I clean out my own. Each time I have, I&#8217;ve lost my Notepad++ FTP synchronize settings.</p>
<p>In Vista they can be found in:<br />
<strong>C:\Users\AppData\Roaming\Notepad++\plugins\config\FTP_synchronize.ini</strong></p>
<p><a href="http://www.beginnercode.com/wp-content/imgupload/2009/08/notepadFTPBackup.jpg"><img src="http://www.beginnercode.com/wp-content/imgupload/2009/08/notepadFTPBackup.jpg" alt="notepadFTPBackup" title="notepadFTPBackup" width="425" height="320" class="aligncenter size-full wp-image-204" /></a></p>
<p>Copy them to backup and replace. In case an update gets hosed, or you are re-installing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2009/08/04/backup-your-notepad-ftp-items/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Get Acrobat Reader WITHOUT Adobe Update manager</title>
		<link>http://www.beginnercode.com/2009/07/30/get-acrobat-reader-without-adobe-update-manager/</link>
		<comments>http://www.beginnercode.com/2009/07/30/get-acrobat-reader-without-adobe-update-manager/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 13:16:50 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=198</guid>
		<description><![CDATA[Recently I&#8217;ve been helping out friends and relations reformat a few computers. They are older, but are speedy enough for their basic needs. One of the sick system hogs (I&#8217;ve found) is the adobe update manager.
Most browsers come with update managers, so I feel the update manager is bloated and not necessary. It likes to [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been helping out friends and relations reformat a few computers. They are older, but are speedy enough for their basic needs. One of the sick system hogs (I&#8217;ve found) is the adobe update manager.</p>
<p>Most browsers come with update managers, so I feel the update manager is bloated and not necessary. It likes to place its services in the startup causing unneeded processing power. </p>
<p>When it came to reformatting my own laptop, there was no way I was going to install acrobat reader from adobe using their typical download page. Which incidentally, if your not careful will also install a toolbar. You need to uncheck that option.</p>
<p>Adobe does have a page where you can download directly without the ridiculous manager. Hat tip to <a href="http://www.walkernews.net/2007/06/21/all-version-adobe-reader-direct-download/">Walker News</a>, who provided me with the adobe direct download link. (<a href="http://get.adobe.com/reader/otherversions/">http://get.adobe.com/reader/otherversions/</a>).</p>
<p><b>UPDATE: </b> This no longer works. I now run older versions from old version.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2009/07/30/get-acrobat-reader-without-adobe-update-manager/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>php: Checking if a directory is empty</title>
		<link>http://www.beginnercode.com/2008/02/21/php-checking-if-a-directory-is-empty/</link>
		<comments>http://www.beginnercode.com/2008/02/21/php-checking-if-a-directory-is-empty/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 15:16:19 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/index.php/2008/02/21/php-checking-if-a-directory-is-empty/</guid>
		<description><![CDATA[I found myself working with text files a little more recently and was looking for a way to tell if a directory was empty. Why? In my case I wanted to check if a directory was empty. If it wasn&#8217;t, to grab the data in those files and put them in a database.
What I didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I found myself working with text files a little more recently and was looking for a way to tell if a directory was empty. Why? In my case I wanted to check if a directory was empty. If it wasn&#8217;t, to grab the data in those files and put them in a database.</p>
<p>What I didn&#8217;t want to do was have the expense of connecting to a database if the directory didn&#8217;t have any files in it to begin with. After chatting with my good friend TDavid at <a href="http://www.php-scripts.com/">php-scripts.com</a>, I decide to run with his suggestion&#8230;</p>
<p>Fill (or don&#8217;t fill) a variable with information if there were files in the directory. Then test the var to confirm or deny if there are files in the directory. It&#8217;s really a small bit of code&#8230;</p>
<pre class="brush: php;">
//----- Check if ticket dir has files. If it has files,
// set a variable to hold the list of file names.

$dir = &quot;../path/to/my/textfiles&quot;;      // set directory

if($handle = opendir($dir)){           // open directory

	while(($file = readdir($handle)) !== false){
		if($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot;){
			$file_list[] = $file;  // Set file list variable
		}

	}

	closedir($handle);      // Close directory
}
</pre>
<p>If there are files in this directory, the variable $file_list would not only exist, but also contain files. For example&#8230;</p>
<pre class="brush: php;">
Array
(
    [0] =&gt; 195972.txt
    [1] =&gt; 196027.txt
    [2] =&gt; 196053.txt
    [3] =&gt; 196067.txt...
)
</pre>
<p>If there aren&#8217;t any files in this directory, the variable $file_list would not even exist because no $file would be inserted into it. At this point we can check/ test the variable to output or do further processing&#8230;</p>
<pre class="brush: php;">
if(isset($file_list)){
    echo &quot;This dir has files!&quot;;
    // perform further processing
    // eg: collect each files contents
} else {
    echo &quot;This dir has NO files!&quot;;
    // stop processing
    // Not much do do with this since there are no files
}
</pre>
<p>Of course there are a few ways of checking to see if a directory is empty, but this way seemed to be the most simplistic to me. If you wanted to you could turn the entire lot into a function for reuse, and less script code clutter.</p>
<p>Comments? Questions?</p>
<p><tags>php, empty directory</tags></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2008/02/21/php-checking-if-a-directory-is-empty/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MySQL Conditional Insert</title>
		<link>http://www.beginnercode.com/2007/12/20/mysql-conditional-insert/</link>
		<comments>http://www.beginnercode.com/2007/12/20/mysql-conditional-insert/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 22:13:05 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php Snippets]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/index.php/2007/12/20/mysql-conditional-insert/</guid>
		<description><![CDATA[I came across a situation where I needed to pull records from 1 db to another on a recurring basis. I read many different ways to do it via searching around the net. Some of the suggestions included creating a temporary table and copying it over. What was lacking was that sometimes the new table [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a situation where I needed to pull records from 1 db to another on a recurring basis. I read many different ways to do it via searching around the net. Some of the suggestions included creating a temporary table and copying it over. What was lacking was that sometimes the new table also needed to be UPDATED, as the information changed from the original table.</p>
<p>I&#8217;ve come up with a dirty little example to show this can be done. There are <i>more</i> keywords that can enhance the <b><a href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html">ON DUPLICATE KEY UPDATE</a></b> function even more. The Example is assuming an &#8220;employees&#8221; table that looks like so:</p>
<table style="border-collapse:collapse;border:1px solid #000;">
<tr>
<th>employees</th>
</tr>
<tr>
<td style ="border:1px solid #000;">id (PK)</td>
</tr>
<tr>
<td style="border:1px solid #000;">first_name</td>
</tr>
</table>
<p>For brevity, I&#8217;ve left out connection data etc;</p>
<pre class="brush: php;">
$myArray = array(0 =&gt; array('id' =&gt; '1', 'fname' =&gt; 'Steve'),
                      array('id' =&gt; '2', 'fname' =&gt; 'sara'),
                      array('id' =&gt; '3', 'fname' =&gt; 'Matt')
                 );

// Don't forget to validate &amp; clean your data
// Connect to db here 

foreach($myArray as $key =&gt; $value){
          $query = &quot;INSERT INTO employees
          (id, first_name) VALUES ('$value[id]', '$value[fname]')
          ON DUPLICATE KEY UPDATE first_name = '$value[fname]'&quot;;

          $result = mysql_query($query);

          if(!$result){

                    print(&quot;Problem: &quot; . mysql_error() . &quot;&quot;);
          } else {

                    print(&quot;Success !&quot;);
          }

}
</pre>
<p>Read the manual on this for more information. This snippet will INSERT if a UNIQUE (in this case &#8216;id&#8217;) does not exist. It will UPDATE any existing unique. In this case any existing &#8216;id&#8217;s, the &#8216;first_name&#8217; column will get updated. </p>
<p>One could also use the <b><a href="http://dev.mysql.com/doc/refman/5.0/en/replace.html">REPLACE</a></b> function. As I understand the difference, REPLACE will DELETE any matching uniques, and INSERT a new record in it&#8217;s place.</p>
<p>Comments? Better ways? I&#8217;m always up for learning something new so please chime in ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2007/12/20/mysql-conditional-insert/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>php: Installing imagick extension on WindowsXP</title>
		<link>http://www.beginnercode.com/2007/10/12/php-installing-imagick-extension-on-windowsxp/</link>
		<comments>http://www.beginnercode.com/2007/10/12/php-installing-imagick-extension-on-windowsxp/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 16:39:40 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/index.php/2007/10/12/php-installing-imagick-extension-on-windowsxp/</guid>
		<description><![CDATA[This may seem simple enough to many programmers out there but this threw me for a few days. This is how you install imagick on a windows server. If your site is on a shared host, you need to ask your host to install the extension for you.
For this example I am running php 5.2.4 [...]]]></description>
			<content:encoded><![CDATA[<p>This may seem simple enough to many programmers out there but this threw me for a few days. This is how you install imagick on a windows server. If your site is on a shared host, you need to ask your host to install the extension for you.</p>
<p>For this example I am running <a href="http://www.php.net/">php</a> 5.2.4 on <a href="http://www.aprelium.com/">Abyss</a>/Apache web server</p>
<p>Download the matching pecl5 Binary <a href="http://www.php.net/downloads.php">from php.net</a>. In this case its pecl5.2-win32-200710121230.zip (matching my current php version).</p>
<p>Unpack the file.</p>
<p>Copy the php&#95;imagick.dll into php/ext/ directory</p>
<p><img src='http://www.beginnercode.com/wp-content/imgupload/2007/10/addphpextension_dll.jpg' alt='php pecl dll' /></p>
<p>Open your php.ini file and look for the &#8220;Dynamic Extensions&#8221; area. In there will be a list of items (some commented out). Add the following line to the bottom of the list: extension=php&#95;imagick.dll</p>
<p><img src='http://www.beginnercode.com/wp-content/imgupload/2007/10/addphpextension_ini.jpg' alt='Add the extension to your ini' /></p>
<p>Save the changes you made.</p>
<p>Restart your web server.</p>
<p>If these steps were successful imagick will show up on any php page using the phpinfo() function.</p>
<p><img src='http://www.beginnercode.com/wp-content/imgupload/2007/10/imagickphpinfo.jpg' alt='imagick in the phpinfo()' /></p>
<p><tags>imagick, pecl-extension, php-extension</tags></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2007/10/12/php-installing-imagick-extension-on-windowsxp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

