<?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"
	>

<channel>
	<title>Brainstorms of a Webdev</title>
	<atom:link href="http://www.bswebdev.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bswebdev.com</link>
	<description>Web development, PHP, Security, etc... etc...</description>
	<pubDate>Sun, 01 Jun 2008 03:37:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>sql file splitter to the rescue</title>
		<link>http://www.bswebdev.com/2008/05/sql-file-splitter-to-the-rescue/</link>
		<comments>http://www.bswebdev.com/2008/05/sql-file-splitter-to-the-rescue/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 03:37:25 +0000</pubDate>
		<dc:creator>tarnus</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[large file mysql importer]]></category>

		<category><![CDATA[mysql dump]]></category>

		<category><![CDATA[sql splitter]]></category>

		<guid isPermaLink="false">http://www.bswebdev.com/?p=19</guid>
		<description><![CDATA[<h3>My Adventures in sql dumping and database migration</h3>
<p><br><br />
My latest problem project presented itself as a phpbb conversion.    The client was having some issues with the old versions of <a href="http://www.phpbb.com" target="_blank">phpbb</a> so we elected to move them to the new version.   While this is a great idea on the surface I did not realize how big the database was.    I started out doing an export using <a href="http://www.phpmyadmin.net/home_page/index.php" target="_blank">phpMyAdmin</a> not knowing the file sizes I was dealing with.  When that failed I decided to do a mysqldump from the shell.    Imagine the look of shock and dumbfoundedness on my face when I finished the dump to discover a 300 meg + sql file.</p>
<p>Why is this a problem?  Well most ISPs have upload limits usually under 20meg for import uploads using phpMyAdmin.  My default install of <a href="http://www.apachefriends.org/en/xampp.html" target="_blank">Xampp</a> limit is 16 meg.   I decided to try to gzip the file with a 100meg + result.    At least now I could download the file to my local machine to try to figure out what to do.</p>
<h4>First Trial PhpMyAdmin Local File upload</h4>
<p>I edited my php.ini files and change the file_upload,  and max_execution time to try and enable a way to upload the file.</p>
<pre class="php">max_execution_time = <span style="color: #cc66cc;">560</span>
max_input_time = <span style="color: #cc66cc;">160</span>
memory_limit = 60M
upload_max_filesize = 160M
&nbsp;</pre>
<p>After an hour of battling the settings to try and get one that would work, I had to read some phpMyadmin documentation and see if I could find a solution.</p>
<div style="float:right;"></div>
<p><strong>PhpMyAdmin Config Change</strong><br />
My first config setting change was a nice config setting called $cfg['UploadDir'].  With this option set to a local server folder, you can select a direct data upload from a local drive.  When you open phpMyAdmin it will give you a list of files to select from in the folder.  You can then select the file and it will perform a direct import of the larger than limit sql file.    However, this still didn't solve the timeout problems with a 100meg sql file.  I had to look further.</p>
<h4>SQL file splitter</h4>
<p>After kicking around some work a rounds, I realized the only way to beat this, was to split the file into parts.    I can either do this by hand, or find a solution.</p>
<p>Google is a wonderful tool for finding things and it didn't let me down this time either.</p>
<p>I found a blog the outlined exactly what I was looking for: <a href="http://www.rusiczki.net/blog/archives/2007/01/24/sql_dump_file_splitter" target="_blank"> Sql file splitter</a> From reviewing his blog It appeared he had the exact same issues I had.   The solution was a program called SQLDumpSplitter 2, by Philip Lehmann-Böhm (<a href="http://www.philiplb.de/">http://www.philiplb.de</a>).    The main links on the blog no longer worked, but a dutch website had left a blog comment with a direct link to the file.   You can download from here:<a href="http://ep2up.com/jasper/upload/1194392686.rar" target="_blank"> Sqldumpsplitter2</a> Hopefully that file link will stick around for a while.</p>
<p>I split the 300 meg file into 23 16-meg chunks.    This worked very well,  I was able to import the large 300 meg file, but it still took baby sitting and remembering what the last file I used was.   In fact I spent several hours importing and then still experienced some time out issues.</p>
<p>I then decided to see if I could find another solution, so it was back to google.</p>
<h4>php mysql large file importer</h4>
<p>was the keyword search I did.     What I found was this blog: <a href="http://www.wanderings.net/notebook/Main/HowToImportLargeMySQLDataFiles" target="_blank">How to import large mysql data files</a>.  This <strong>WAS</strong> the solution to all my problems!!! In this blog, there was a link to a site and a program called <a href="http://www.ozerov.de/bigdump.php" target="_blank">Bigdump.</a></p>
<p><a href="http://www.ozerov.de/bigdump.php" target="_blank"></a> Bigdump is a staggered mysql dump importer.     What this means, is you start the file, and it will automatically import the large file till it is complete.    That means, no file splitting.  It is truly an amazing piece of 10K of code.</p>
<p>To import a large file you perform the following steps:</p>
<pre>1 - Copy bigdump.php to the website where you want to import the file.
2 - If the file size is larger that the upload limit of the server, copy the
    file to the same foldere.
3 - Edit the bigdump.php file, set the database name, the username and password.
4 - If the file size is larger than the limit, enter the filename into the
    &quot;filename&quot; field.
5 - Execute the bigdump file by going to http://yourdomainlocation/bigdump.com
6 - Wait for the import to complete and be prepared for the shock and awe.
&nbsp;</pre>
<p>For my test I used the uncompressed 300 meg sql file.   The documentation states, you can use the gzipped version also.    It took approx 15 minutes or less, to import that file with the bigdump program.   I still am amazed.    Had I found this earlier today, this blog may not actually exist.</p>
<p>Hurrah for Bigdump!!!!  I gladly sent a paypal donation for this code!   It saved my life.</p>
<p>I hope that the  users that are looking for a sql splitter will find this blog and save themselves the initial headaches I had.</p>
<p><a href="http://www.bswebdev.com/wp-content/uploads/2008/05/2008-05-31_215750.jpg"><img class="aligncenter size-full wp-image-20" title="Bigdump" src="http://www.bswebdev.com/wp-content/uploads/2008/05/2008-05-31_215750.jpg" alt="" width="500" height="284" /></a></p>
]]></description>
			<content:encoded><![CDATA[<h3>My Adventures in sql dumping and database migration</h3>
<p><br><br />
My latest problem project presented itself as a phpbb conversion.    The client was having some issues with the old versions of <a href="http://www.phpbb.com" target="_blank">phpbb</a> so we elected to move them to the new version.   While this is a great idea on the surface I did not realize how big the database was.    I started out doing an export using <a href="http://www.phpmyadmin.net/home_page/index.php" target="_blank">phpMyAdmin</a> not knowing the file sizes I was dealing with.  When that failed I decided to do a mysqldump from the shell.    Imagine the look of shock and dumbfoundedness on my face when I finished the dump to discover a 300 meg + sql file.</p>
<p>Why is this a problem?  Well most ISPs have upload limits usually under 20meg for import uploads using phpMyAdmin.  My default install of <a href="http://www.apachefriends.org/en/xampp.html" target="_blank">Xampp</a> limit is 16 meg.   I decided to try to gzip the file with a 100meg + result.    At least now I could download the file to my local machine to try to figure out what to do.</p>
<h4>First Trial PhpMyAdmin Local File upload</h4>
<p>I edited my php.ini files and change the file_upload,  and max_execution time to try and enable a way to upload the file.</p>
<pre class="php">max_execution_time = <span style="color: #cc66cc;">560</span>
max_input_time = <span style="color: #cc66cc;">160</span>
memory_limit = 60M
upload_max_filesize = 160M
&nbsp;</pre>
<p>After an hour of battling the settings to try and get one that would work, I had to read some phpMyadmin documentation and see if I could find a solution.</p>
<div style="float:right;"></div>
<p><strong>PhpMyAdmin Config Change</strong><br />
My first config setting change was a nice config setting called $cfg['UploadDir'].  With this option set to a local server folder, you can select a direct data upload from a local drive.  When you open phpMyAdmin it will give you a list of files to select from in the folder.  You can then select the file and it will perform a direct import of the larger than limit sql file.    However, this still didn't solve the timeout problems with a 100meg sql file.  I had to look further.</p>
<h4>SQL file splitter</h4>
<p>After kicking around some work a rounds, I realized the only way to beat this, was to split the file into parts.    I can either do this by hand, or find a solution.</p>
<p>Google is a wonderful tool for finding things and it didn't let me down this time either.</p>
<p>I found a blog the outlined exactly what I was looking for: <a href="http://www.rusiczki.net/blog/archives/2007/01/24/sql_dump_file_splitter" target="_blank"> Sql file splitter</a> From reviewing his blog It appeared he had the exact same issues I had.   The solution was a program called SQLDumpSplitter 2, by Philip Lehmann-Böhm (<a href="http://www.philiplb.de/">http://www.philiplb.de</a>).    The main links on the blog no longer worked, but a dutch website had left a blog comment with a direct link to the file.   You can download from here:<a href="http://ep2up.com/jasper/upload/1194392686.rar" target="_blank"> Sqldumpsplitter2</a> Hopefully that file link will stick around for a while.</p>
<p>I split the 300 meg file into 23 16-meg chunks.    This worked very well,  I was able to import the large 300 meg file, but it still took baby sitting and remembering what the last file I used was.   In fact I spent several hours importing and then still experienced some time out issues.</p>
<p>I then decided to see if I could find another solution, so it was back to google.</p>
<h4>php mysql large file importer</h4>
<p>was the keyword search I did.     What I found was this blog: <a href="http://www.wanderings.net/notebook/Main/HowToImportLargeMySQLDataFiles" target="_blank">How to import large mysql data files</a>.  This <strong>WAS</strong> the solution to all my problems!!! In this blog, there was a link to a site and a program called <a href="http://www.ozerov.de/bigdump.php" target="_blank">Bigdump.</a></p>
<p><a href="http://www.ozerov.de/bigdump.php" target="_blank"></a> Bigdump is a staggered mysql dump importer.     What this means, is you start the file, and it will automatically import the large file till it is complete.    That means, no file splitting.  It is truly an amazing piece of 10K of code.</p>
<p>To import a large file you perform the following steps:</p>
<pre>1 - Copy bigdump.php to the website where you want to import the file.
2 - If the file size is larger that the upload limit of the server, copy the
    file to the same foldere.
3 - Edit the bigdump.php file, set the database name, the username and password.
4 - If the file size is larger than the limit, enter the filename into the
    &quot;filename&quot; field.
5 - Execute the bigdump file by going to http://yourdomainlocation/bigdump.com
6 - Wait for the import to complete and be prepared for the shock and awe.
&nbsp;</pre>
<p>For my test I used the uncompressed 300 meg sql file.   The documentation states, you can use the gzipped version also.    It took approx 15 minutes or less, to import that file with the bigdump program.   I still am amazed.    Had I found this earlier today, this blog may not actually exist.</p>
<p>Hurrah for Bigdump!!!!  I gladly sent a paypal donation for this code!   It saved my life.</p>
<p>I hope that the  users that are looking for a sql splitter will find this blog and save themselves the initial headaches I had.</p>
<p><a href="http://www.bswebdev.com/wp-content/uploads/2008/05/2008-05-31_215750.jpg"><img class="aligncenter size-full wp-image-20" title="Bigdump" src="http://www.bswebdev.com/wp-content/uploads/2008/05/2008-05-31_215750.jpg" alt="" width="500" height="284" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bswebdev.com/2008/05/sql-file-splitter-to-the-rescue/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Palm Centro, my new phone</title>
		<link>http://www.bswebdev.com/2008/05/palm-centro/</link>
		<comments>http://www.bswebdev.com/2008/05/palm-centro/#comments</comments>
		<pubDate>Mon, 19 May 2008 14:15:24 +0000</pubDate>
		<dc:creator>tarnus</dc:creator>
		
		<category><![CDATA[Electronics]]></category>

		<category><![CDATA[cell phone]]></category>

		<category><![CDATA[Palm]]></category>

		<category><![CDATA[smart phone]]></category>

		<guid isPermaLink="false">http://www.bswebdev.com/?p=9</guid>
		<description><![CDATA[<p>WOOT!!  I got a new phone!   Only reason I did, was I broke my Treo 650 a second time.   Same issue, I managed to short out the headphone jack.   I don't know why they bother to put them on,  if they don't give them more industrial strength.     I checked with AT&amp;T online and found I was eligible for a new phone.</p>
<p>Smart Phone Choices have grown with leap and bounds.  The top ones are Iphone, Blackberry, Treo just to name a few.  I really thought I might wait for a cheaper version of the Iphone, but I've been a Palm person for years, that and right now the Iphone is about $200 more than I wanted to spend.</p>
<p><a href="http://www.bswebdev.com/wp-content/uploads/2008/05/palm1.jpg"><img class="alignnone size-medium wp-image-10" style="margin: 5px; float: left;" title="Centro vs Treo" src="http://www.bswebdev.com/wp-content/uploads/2008/05/palm1.jpg" alt="" width="212" height="209" /></a>After a little research I decided to go with the Palm Centro, most of the reviews compared it to the Treo 680, and since I was just leaving a 650 it sounded like the most economical choice.    The Phone with a new contract is $199, but you can get a $100 rebate if you get it with a data plan.  At $99 its gotta be one of the cheapest choices of smart phones on the market.</p>
<p>The Palm Centro is by far the smallest smart phone that I have seen.   Its an amazing difference in size to my Treo 650.   As you can see in the picture.      It reminds me of my first small nokia phone,   I can more easily put it in a shirt or pants pocket where with the treo,  it was just very bulky.</p>
<p>One of the selling points for me was it has an optional micro SD port.    Now I can move all the data, and media from my old phones SD fairly easily to the new phone.  The pricing of SD and micro-SD has dropped significatly from when I bought my last 1gig.   I had  paid near a hundred dollars about 2 years ago.   I found a  4gig micro SD for $27 shipped  this more than compensated for the fact I had to buy a micro instead of a regular SD ram.     I love ever changing technology.   Makes my toys MUCH cheaper.</p>
<p><a href="http://www.bswebdev.com/wp-content/uploads/2008/05/palmkey.jpg"><img style="margin: 3px 5px; float: right;" title="Centro Keyboard" src="http://www.bswebdev.com/wp-content/uploads/2008/05/palmkey-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p><strong>The Keyboard</strong><br />
While the keys are closer together, they actually still very  easy to get to,  either that or I have just gotten better at typing on small keyboards.   One cool difference is they added a menu button. On the treo there wasn't one, and it was rather annoying when the app wouldn't let you easily get to the menus.  I can quickly type and get to menu functions even one-handed.</p>
<p><strong>Minor Issues</strong><br />
One of the few issues I have had is I could not get the SMS messages to work with my Agendus Mail.  Not a real big deal, just couldn't figure out where my SMS messages were going when I received them.   Once I removed and reinstalled Agendus Mail without the SMS option it fixed the problem.</p>
<p><strong>The Camera<br />
</strong>The camera has been upgraded to a 1.3 MP camera, pictures are fantastic compared to the Treo 640.</p>
<p><a href="http://www.bswebdev.com/wp-content/uploads/2008/05/palmhand.jpg"><img style="margin: 3px 5px; float: left;" title="palmhand" src="http://www.bswebdev.com/wp-content/uploads/2008/05/palmhand-150x150.jpg" alt="" width="150" height="150" /></a><strong>Data Package<br />
</strong>Due to the discount requirements I had to buy the data package.  My issues with it right now is I have a hard time paying $30/month for unlimited internet when its as slow as it is.  Hopefully the speed will be taken care of over time, but when your spoiled with 10 MB Cable speeds, its hard to deal with at times.   The Web browser works fairly well, I can use most of the google mobile web applications with very little problems.   The built in IM software is currently working off and on I am unsure if thats due to the network or the software.</p>
<p>Overall I absolutely love the phone.  It is light weight, small and fits in my pocket easily.  Works better than my treo 650.  Half the time, no one even knows its a smart phone.   In the world where some think bigger is better this small phone is incredible for the price.</p>
]]></description>
			<content:encoded><![CDATA[<p>WOOT!!  I got a new phone!   Only reason I did, was I broke my Treo 650 a second time.   Same issue, I managed to short out the headphone jack.   I don't know why they bother to put them on,  if they don't give them more industrial strength.     I checked with AT&amp;T online and found I was eligible for a new phone.</p>
<p>Smart Phone Choices have grown with leap and bounds.  The top ones are Iphone, Blackberry, Treo just to name a few.  I really thought I might wait for a cheaper version of the Iphone, but I've been a Palm person for years, that and right now the Iphone is about $200 more than I wanted to spend.</p>
<p><a href="http://www.bswebdev.com/wp-content/uploads/2008/05/palm1.jpg"><img class="alignnone size-medium wp-image-10" style="margin: 5px; float: left;" title="Centro vs Treo" src="http://www.bswebdev.com/wp-content/uploads/2008/05/palm1.jpg" alt="" width="212" height="209" /></a>After a little research I decided to go with the Palm Centro, most of the reviews compared it to the Treo 680, and since I was just leaving a 650 it sounded like the most economical choice.    The Phone with a new contract is $199, but you can get a $100 rebate if you get it with a data plan.  At $99 its gotta be one of the cheapest choices of smart phones on the market.</p>
<p>The Palm Centro is by far the smallest smart phone that I have seen.   Its an amazing difference in size to my Treo 650.   As you can see in the picture.      It reminds me of my first small nokia phone,   I can more easily put it in a shirt or pants pocket where with the treo,  it was just very bulky.</p>
<p>One of the selling points for me was it has an optional micro SD port.    Now I can move all the data, and media from my old phones SD fairly easily to the new phone.  The pricing of SD and micro-SD has dropped significatly from when I bought my last 1gig.   I had  paid near a hundred dollars about 2 years ago.   I found a  4gig micro SD for $27 shipped  this more than compensated for the fact I had to buy a micro instead of a regular SD ram.     I love ever changing technology.   Makes my toys MUCH cheaper.</p>
<p><a href="http://www.bswebdev.com/wp-content/uploads/2008/05/palmkey.jpg"><img style="margin: 3px 5px; float: right;" title="Centro Keyboard" src="http://www.bswebdev.com/wp-content/uploads/2008/05/palmkey-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p><strong>The Keyboard</strong><br />
While the keys are closer together, they actually still very  easy to get to,  either that or I have just gotten better at typing on small keyboards.   One cool difference is they added a menu button. On the treo there wasn't one, and it was rather annoying when the app wouldn't let you easily get to the menus.  I can quickly type and get to menu functions even one-handed.</p>
<p><strong>Minor Issues</strong><br />
One of the few issues I have had is I could not get the SMS messages to work with my Agendus Mail.  Not a real big deal, just couldn't figure out where my SMS messages were going when I received them.   Once I removed and reinstalled Agendus Mail without the SMS option it fixed the problem.</p>
<p><strong>The Camera<br />
</strong>The camera has been upgraded to a 1.3 MP camera, pictures are fantastic compared to the Treo 640.</p>
<p><a href="http://www.bswebdev.com/wp-content/uploads/2008/05/palmhand.jpg"><img style="margin: 3px 5px; float: left;" title="palmhand" src="http://www.bswebdev.com/wp-content/uploads/2008/05/palmhand-150x150.jpg" alt="" width="150" height="150" /></a><strong>Data Package<br />
</strong>Due to the discount requirements I had to buy the data package.  My issues with it right now is I have a hard time paying $30/month for unlimited internet when its as slow as it is.  Hopefully the speed will be taken care of over time, but when your spoiled with 10 MB Cable speeds, its hard to deal with at times.   The Web browser works fairly well, I can use most of the google mobile web applications with very little problems.   The built in IM software is currently working off and on I am unsure if thats due to the network or the software.</p>
<p>Overall I absolutely love the phone.  It is light weight, small and fits in my pocket easily.  Works better than my treo 650.  Half the time, no one even knows its a smart phone.   In the world where some think bigger is better this small phone is incredible for the price.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bswebdev.com/2008/05/palm-centro/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP day count and date comparison</title>
		<link>http://www.bswebdev.com/2008/05/php-day-count-and-date-comparison/</link>
		<comments>http://www.bswebdev.com/2008/05/php-day-count-and-date-comparison/#comments</comments>
		<pubDate>Tue, 13 May 2008 14:52:11 +0000</pubDate>
		<dc:creator>tarnus</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[php date]]></category>

		<guid isPermaLink="false">http://www.bswebdev.com/?p=12</guid>
		<description><![CDATA[<p>Dealing with date based data can be a mind numbing experience.   Calculation date differences, doing date comparisons can really stretch you to the limits at times.  There is a variety of ways to deal with date based data but the first step usually is to convert it into a standard format that you can easily deal with.  That format is the unix timestamp.</p>
<p>The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch.</p>
<p>Below is a code snippet for creating a timestamp from formatted date data.  For this example the date_in variable contains a date in the format of YYYY-MM-DD and is passed from a previously executed form post.</p>
<pre class="php"><span style="color: #0000ff;">$datearray</span>=<a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span>,<span style="color: #0000ff;">$_POST</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'date_in'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$year</span>=<span style="color: #0000ff;">$datearray</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$month</span>=<span style="color: #0000ff;">$datearray</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$day</span>=<span style="color: #0000ff;">$datearray</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$mytimestamp</span>=<a href="http://www.php.net/mktime"><span style="color: #000066;">mktime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #0000ff;">$month</span>,<span style="color: #0000ff;">$day</span><span style="color: #0000ff;">$year</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Recently I discovered an easier way to get a date converted to a timestamp.  This just goes to show you that a programmer is always learning.  There will always be functions that are overlooked and underused.</p>
<p><a href="http://us2.php.net/strtotime" target="_blank"><strong>strtotime() function</strong></a> this function will take an english based date format and convert it to timestamp.  The code below illustrates how much easier this is.</p>
<pre class="php"><span style="color: #0000ff;">$mytimestamp</span>=<a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_POST</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'date_in'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>One line of code!  No exploding parts, just a quick and easy solution.</p>
<h4>Calculate Number of days</h4>
<p>Now that timestamps have been reviewed to show you some easy way to take two days and return a total number of days.  The example below will take an arbitrary date of April 4, 2008 and May 12, 2008 (the current date I wrote the article)</p>
<pre class="php"><span style="color: #0000ff;">$time_A</span> = <a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;April 4, 2008&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$time_B</span>=<a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span>now<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$numdays</span>=<a href="http://www.php.net/intval"><span style="color: #000066;">intval</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$time_B</span>-<span style="color: #0000ff;">$time_A</span><span style="color: #66cc66;">&#41;</span>/<span style="color: #cc66cc;">86400</span><span style="color: #66cc66;">&#41;</span><span style="color: #cc66cc;">+1</span>;</pre>
<p>The number of seconds in a day is 86400 and the calculations usually shorts you a day so thats why we add a 1.  This is do the fact the now() returns the current time which is not a complete day.</p>
<p>Another example of using date comparisons is expiring accounts in a database.  If you can let the database do the work for you, DO IT, as anytime you can save code calculations the easier it is on you. This code will take the current date and compare it to the user_expdate and delete those records that are less than or equal to 0.</p>
<pre class="php"> <span style="color: #0000ff;">$current_date</span>=<a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Y-m-d G:i:s&quot;</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
  <span style="color: #0000ff;">$query</span>=<span style="color: #ff0000;">&quot;delete from {$db_prefix}users where user_expdate!='0000-00-00
 00:00:00' and datediff(user_expdate,'&quot;</span>.<span style="color: #0000ff;">$current_date</span>.<span style="color: #ff0000;">&quot;')&amp;lt;= 0 &quot;</span>;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$result</span>=<span style="color: #0000ff;">$db</span>-&amp;gt;execute<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$db</span>-&amp;gt;ErrorMsg<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span></pre>
<h4>Date comparisons</h4>
<p>Date comparisons are now simple a matter of comparing the timestamps.  Given  2 timestamps you can compare them and know very simply which is greater.  Note: in the example below we forced the today variable to midnight so only days before the two timestamps are selected.</p>
<pre class="php"><span style="color: #0000ff;">$today</span>=<a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Y-m-d&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; 00:00:00&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$datecheck</span> = <a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$year</span>.<span style="color: #ff0000;">&quot;-&quot;</span>.<span style="color: #0000ff;">$month</span>.<span style="color: #ff0000;">&quot;-&quot;</span>.<span style="color: #0000ff;">$day</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$datecheck</span> &amp;lt; <span style="color: #0000ff;">$today</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
     <span style="color: #808080; font-style: italic;">//find all dates before today and block them out</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>Date comparisons in mysql can be done similarly.  However mysql give a variety of date tools to work with as you are calculating dates.</p>
<p>The following code snipplet shows a way to delete code based on a timestamp comparison.   Note:  The code uses <a href="http://adodblite.sourceforge.net/index.php" target="_blank">ADODB Lite</a> calls.  The $db-&gt;qstr function add's the appropriate quote code.</p>
<pre class="php"><span style="color: #0000ff;">$today</span>=<a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Y-m-d&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; 00:00:00&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
 <span style="color: #0000ff;">$query</span>=<span style="color: #ff0000;">&quot;delete from {$db_prefix}users where user_expdate!='0000-00-00
 00:00:00' and timestamp(user_expdate) &amp;lt; &quot;</span>.<span style="color: #0000ff;">$db</span>-&amp;gt;qstr<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$today</span><span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;;
  if (!$result=$db-&amp;gt;execute($query)){
    $db-&amp;gt;ErrorMsg();
  }
</span></pre>
<p>While these are some basic ways to do this, there are many other ways.  I always welcome comments, feel free to add your own two cents.  </p>
<p>Just make sure you register as No Spammers are allowed.</p>
]]></description>
			<content:encoded><![CDATA[<p>Dealing with date based data can be a mind numbing experience.   Calculation date differences, doing date comparisons can really stretch you to the limits at times.  There is a variety of ways to deal with date based data but the first step usually is to convert it into a standard format that you can easily deal with.  That format is the unix timestamp.</p>
<p>The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch.</p>
<p>Below is a code snippet for creating a timestamp from formatted date data.  For this example the date_in variable contains a date in the format of YYYY-MM-DD and is passed from a previously executed form post.</p>
<pre class="php"><span style="color: #0000ff;">$datearray</span>=<a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span>,<span style="color: #0000ff;">$_POST</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'date_in'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$year</span>=<span style="color: #0000ff;">$datearray</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$month</span>=<span style="color: #0000ff;">$datearray</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$day</span>=<span style="color: #0000ff;">$datearray</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$mytimestamp</span>=<a href="http://www.php.net/mktime"><span style="color: #000066;">mktime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #0000ff;">$month</span>,<span style="color: #0000ff;">$day</span><span style="color: #0000ff;">$year</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Recently I discovered an easier way to get a date converted to a timestamp.  This just goes to show you that a programmer is always learning.  There will always be functions that are overlooked and underused.</p>
<p><a href="http://us2.php.net/strtotime" target="_blank"><strong>strtotime() function</strong></a> this function will take an english based date format and convert it to timestamp.  The code below illustrates how much easier this is.</p>
<pre class="php"><span style="color: #0000ff;">$mytimestamp</span>=<a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_POST</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'date_in'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>One line of code!  No exploding parts, just a quick and easy solution.</p>
<h4>Calculate Number of days</h4>
<p>Now that timestamps have been reviewed to show you some easy way to take two days and return a total number of days.  The example below will take an arbitrary date of April 4, 2008 and May 12, 2008 (the current date I wrote the article)</p>
<pre class="php"><span style="color: #0000ff;">$time_A</span> = <a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;April 4, 2008&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$time_B</span>=<a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span>now<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$numdays</span>=<a href="http://www.php.net/intval"><span style="color: #000066;">intval</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$time_B</span>-<span style="color: #0000ff;">$time_A</span><span style="color: #66cc66;">&#41;</span>/<span style="color: #cc66cc;">86400</span><span style="color: #66cc66;">&#41;</span><span style="color: #cc66cc;">+1</span>;</pre>
<p>The number of seconds in a day is 86400 and the calculations usually shorts you a day so thats why we add a 1.  This is do the fact the now() returns the current time which is not a complete day.</p>
<p>Another example of using date comparisons is expiring accounts in a database.  If you can let the database do the work for you, DO IT, as anytime you can save code calculations the easier it is on you. This code will take the current date and compare it to the user_expdate and delete those records that are less than or equal to 0.</p>
<pre class="php"> <span style="color: #0000ff;">$current_date</span>=<a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Y-m-d G:i:s&quot;</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
  <span style="color: #0000ff;">$query</span>=<span style="color: #ff0000;">&quot;delete from {$db_prefix}users where user_expdate!='0000-00-00
 00:00:00' and datediff(user_expdate,'&quot;</span>.<span style="color: #0000ff;">$current_date</span>.<span style="color: #ff0000;">&quot;')&amp;lt;= 0 &quot;</span>;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$result</span>=<span style="color: #0000ff;">$db</span>-&amp;gt;execute<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$db</span>-&amp;gt;ErrorMsg<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span></pre>
<h4>Date comparisons</h4>
<p>Date comparisons are now simple a matter of comparing the timestamps.  Given  2 timestamps you can compare them and know very simply which is greater.  Note: in the example below we forced the today variable to midnight so only days before the two timestamps are selected.</p>
<pre class="php"><span style="color: #0000ff;">$today</span>=<a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Y-m-d&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; 00:00:00&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$datecheck</span> = <a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$year</span>.<span style="color: #ff0000;">&quot;-&quot;</span>.<span style="color: #0000ff;">$month</span>.<span style="color: #ff0000;">&quot;-&quot;</span>.<span style="color: #0000ff;">$day</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$datecheck</span> &amp;lt; <span style="color: #0000ff;">$today</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
     <span style="color: #808080; font-style: italic;">//find all dates before today and block them out</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>Date comparisons in mysql can be done similarly.  However mysql give a variety of date tools to work with as you are calculating dates.</p>
<p>The following code snipplet shows a way to delete code based on a timestamp comparison.   Note:  The code uses <a href="http://adodblite.sourceforge.net/index.php" target="_blank">ADODB Lite</a> calls.  The $db-&gt;qstr function add's the appropriate quote code.</p>
<pre class="php"><span style="color: #0000ff;">$today</span>=<a href="http://www.php.net/strtotime"><span style="color: #000066;">strtotime</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Y-m-d&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; 00:00:00&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
 <span style="color: #0000ff;">$query</span>=<span style="color: #ff0000;">&quot;delete from {$db_prefix}users where user_expdate!='0000-00-00
 00:00:00' and timestamp(user_expdate) &amp;lt; &quot;</span>.<span style="color: #0000ff;">$db</span>-&amp;gt;qstr<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$today</span><span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;;
  if (!$result=$db-&amp;gt;execute($query)){
    $db-&amp;gt;ErrorMsg();
  }
</span></pre>
<p>While these are some basic ways to do this, there are many other ways.  I always welcome comments, feel free to add your own two cents.  </p>
<p>Just make sure you register as No Spammers are allowed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bswebdev.com/2008/05/php-day-count-and-date-comparison/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Experiments in Domain Parking</title>
		<link>http://www.bswebdev.com/2008/05/experiments-in-domain-parking/</link>
		<comments>http://www.bswebdev.com/2008/05/experiments-in-domain-parking/#comments</comments>
		<pubDate>Thu, 08 May 2008 07:17:27 +0000</pubDate>
		<dc:creator>tarnus</dc:creator>
		
		<category><![CDATA[Domain Names]]></category>

		<category><![CDATA[domain parking]]></category>

		<guid isPermaLink="false">http://blog.oznet.com/?p=6</guid>
		<description><![CDATA[<p>I had just paid for several domains that I had planned to build websites on yet have not had time to do them.  You know web entrepreneurs,  they are always looking for that next great website.</p>
<p>While I am not one that has taken up the reigns of the domain name rush, I was around early enough that I could have grabbed just about anyone that I had wanted.       It's too bad for me that I wasn't the greedy one or I might have got that million dollars I have always wanted.   I have always said its better to be rich than famous.</p>
<p>Well anyways I decided to test domain name parking.   I found that there are many places that you can park a  domain.  Some places require that you have 10 or more to park, others want you to pay a fee.   I opted to use <a href="http://www.namedrive.com/?ref=9223" target="_blank">Name Drive</a> because it was free, and the generated pages actually looked better than some parking sites.</p>
<p>The following domains are ones I have been paying on for years.  I had intended to use them as I described them, I will see if parking can at least pay for the cost of ownership</p>
<p><a href="http://www.maxhotels.com" target="_blank">maxhotels.com</a> - Original plan was to create a site for people to book hotels based on the highest hotel ratings.   It may not be that now,  but at some point I hope I will have time to finish it<br />
<a href="http://www.ozarksgolf.com" target="_blank">ozarksgolf.com</a> - Local golf portal site.  One place you could go to find local golf info<br />
<a href="http://www.ozarksdining.com" target="_blank">ozarksdining.com </a>- Local Restaurant guide<br />
<a href="http://www.ozarksmusic.com" target="_blank">ozarksmusic.com</a> - Whats happening on the local music scene<a href="http://www.ozarksmusic.com" target="_blank"><br />
</a><a href="http://www.sleepysearch.com" target="_blank">sleepysearch.com</a> - Another Hotel site<a href="http://www.sleepysearch.com" target="_blank"><br />
</a><a href="http://www.shoppingsearch.biz" target="_blank">shoppingsearch.biz</a> - Shopping portal</p>
<p>The true test will take a few months.  The hard work begins by trying to get the domains to just show up in search engines.  After that, its just a matter of time to see if this free parking works.</p>
<p>As time permits I may take one domain and populate it myself with google ads and see how well I can do on my own versus the free parking sites.</p>
<p>For those of you that think you want to try your hand at this, the first thing you will need to do is buy several <a href="http://www.snethosting.com" target="_blank">domain names</a>.  Domain names can be bought all over the net, but do a poor programmer a favor and buy it from me at <a href="http://www.snethosting.com" target="_blank">http://www.snethosting.com</a>.  While I don't make alot off of them, maybe I can buy myself lunch or something.</p>
]]></description>
			<content:encoded><![CDATA[<p>I had just paid for several domains that I had planned to build websites on yet have not had time to do them.  You know web entrepreneurs,  they are always looking for that next great website.</p>
<p>While I am not one that has taken up the reigns of the domain name rush, I was around early enough that I could have grabbed just about anyone that I had wanted.       It's too bad for me that I wasn't the greedy one or I might have got that million dollars I have always wanted.   I have always said its better to be rich than famous.</p>
<p>Well anyways I decided to test domain name parking.   I found that there are many places that you can park a  domain.  Some places require that you have 10 or more to park, others want you to pay a fee.   I opted to use <a href="http://www.namedrive.com/?ref=9223" target="_blank">Name Drive</a> because it was free, and the generated pages actually looked better than some parking sites.</p>
<p>The following domains are ones I have been paying on for years.  I had intended to use them as I described them, I will see if parking can at least pay for the cost of ownership</p>
<p><a href="http://www.maxhotels.com" target="_blank">maxhotels.com</a> - Original plan was to create a site for people to book hotels based on the highest hotel ratings.   It may not be that now,  but at some point I hope I will have time to finish it<br />
<a href="http://www.ozarksgolf.com" target="_blank">ozarksgolf.com</a> - Local golf portal site.  One place you could go to find local golf info<br />
<a href="http://www.ozarksdining.com" target="_blank">ozarksdining.com </a>- Local Restaurant guide<br />
<a href="http://www.ozarksmusic.com" target="_blank">ozarksmusic.com</a> - Whats happening on the local music scene<a href="http://www.ozarksmusic.com" target="_blank"><br />
</a><a href="http://www.sleepysearch.com" target="_blank">sleepysearch.com</a> - Another Hotel site<a href="http://www.sleepysearch.com" target="_blank"><br />
</a><a href="http://www.shoppingsearch.biz" target="_blank">shoppingsearch.biz</a> - Shopping portal</p>
<p>The true test will take a few months.  The hard work begins by trying to get the domains to just show up in search engines.  After that, its just a matter of time to see if this free parking works.</p>
<p>As time permits I may take one domain and populate it myself with google ads and see how well I can do on my own versus the free parking sites.</p>
<p>For those of you that think you want to try your hand at this, the first thing you will need to do is buy several <a href="http://www.snethosting.com" target="_blank">domain names</a>.  Domain names can be bought all over the net, but do a poor programmer a favor and buy it from me at <a href="http://www.snethosting.com" target="_blank">http://www.snethosting.com</a>.  While I don't make alot off of them, maybe I can buy myself lunch or something.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bswebdev.com/2008/05/experiments-in-domain-parking/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Javascript Auto Focus Form Element</title>
		<link>http://www.bswebdev.com/2008/05/javascript-autofocus-form-element/</link>
		<comments>http://www.bswebdev.com/2008/05/javascript-autofocus-form-element/#comments</comments>
		<pubDate>Mon, 05 May 2008 13:06:10 +0000</pubDate>
		<dc:creator>tarnus</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[form]]></category>

		<category><![CDATA[input text field]]></category>

		<category><![CDATA[javascrpt]]></category>

		<guid isPermaLink="false">http://www.bswebdev.com/?p=8</guid>
		<description><![CDATA[<p>One of the main reasons I decided to have this blog is to create a reference place so I could easily find code or how to do things from time to time.  Usually I have to sift through code trying to remember the last place I used something.  From here on out I plan on posting code snippets as I run across them.  Today I woke up to an email requesting if a signup form or member login form was opened, they wanted the cursor to automatically focus on the username or the first element of the form.  To be honest, I didn't even know it could be done from a page open.  So the first thing I did was open up Google and search until I find a way.  I an not too ego minded to think I know everything.  There is always someone that has found a better way.  </p>
<p>Here is the JavaScript code:</p>
<p><code class="javascript"><script type="text/javascript">
   function formfocus() {
      document.getElementById('element').focus();
   }
   window.onload = formfocus;
</script></code></p>
<p>Here is the XHTML part of the code:</p>
<pre>&nbsp;
&lt;form&gt;
&lt;input id=&quot;element&quot; /&gt;
&lt;input /&gt;
&lt;input /&gt;
&lt;/form&gt;
&nbsp;</pre>
<p>For those that are a little new to javascript.  The javascript should go in the document HEAD.  The "element" can be changed to the id of the field you are working with.</p>
]]></description>
			<content:encoded><![CDATA[<p>One of the main reasons I decided to have this blog is to create a reference place so I could easily find code or how to do things from time to time.  Usually I have to sift through code trying to remember the last place I used something.  From here on out I plan on posting code snippets as I run across them.  Today I woke up to an email requesting if a signup form or member login form was opened, they wanted the cursor to automatically focus on the username or the first element of the form.  To be honest, I didn't even know it could be done from a page open.  So the first thing I did was open up Google and search until I find a way.  I an not too ego minded to think I know everything.  There is always someone that has found a better way.  </p>
<p>Here is the JavaScript code:</p>
<p><code class="javascript"><script type="text/javascript">
   function formfocus() {
      document.getElementById('element').focus();
   }
   window.onload = formfocus;
</script></code></p>
<p>Here is the XHTML part of the code:</p>
<pre>&nbsp;
&lt;form&gt;
&lt;input id=&quot;element&quot; /&gt;
&lt;input /&gt;
&lt;input /&gt;
&lt;/form&gt;
&nbsp;</pre>
<p>For those that are a little new to javascript.  The javascript should go in the document HEAD.  The "element" can be changed to the id of the field you are working with.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bswebdev.com/2008/05/javascript-autofocus-form-element/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Variable Variables and Template Lite</title>
		<link>http://www.bswebdev.com/2008/05/variable-variables-and-template-lite/</link>
		<comments>http://www.bswebdev.com/2008/05/variable-variables-and-template-lite/#comments</comments>
		<pubDate>Thu, 01 May 2008 14:17:27 +0000</pubDate>
		<dc:creator>tarnus</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Template Lite]]></category>

		<guid isPermaLink="false">http://blog.oznet.com/?p=4</guid>
		<description><![CDATA[<p>There is one programing concept that always hurts my head, and  that is the variable variables or dynamic variables.   What dynamic let you do is access data from the value of the a variable you are viewing.  (See I told you it would hurt your head)</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$b</span> =<span style="color: #cc66cc;">20</span>;  <span style="color: #808080; font-style: italic;">// set the value of b</span>
<span style="color: #0000ff;">$c</span>=<span style="color: #ff0000;">&quot;b&quot;</span>;  <span style="color: #808080; font-style: italic;">// set c to the name of the variable you want to view</span>
<span style="color: #0000ff;">$d</span>=$<span style="color: #66cc66;">&#123;</span><span style="color: #0000ff;">$c</span><span style="color: #66cc66;">&#125;</span>; <span style="color: #808080; font-style: italic;">// the variable variable  $d is now equal to 20</span>
&nbsp;</pre>
<p>Many of you are probably asking yourself, " OK I understand that , but why do I need to do that?"<br />
The number one place I use this, is in a web grid form. Any place you need to update/or delete data in that grid.  Below is an example of what a grid of data may look like:</p>
<p style="text-align: center;"><a href="http://blog.oznet.com/wp-content/uploads/2008/04/datagrid.jpg"><img class="size-full wp-image-5" title="datagrid" src="http://blog.oznet.com/wp-content/uploads/2008/04/datagrid.jpg" alt="Data Grid" width="400" height="222" /></a></p>
<p style="text-align: left;">The issues you face in the above grid is how do I delete multiple items and change multiple elements of data in grid once it is submitted.  The solution is you assign each field a row number and add that to the field name.</p>
<p style="text-align: left;">Example:</p>
<p style="text-align: left;">
<p style="text-align: left;">
<pre>&nbsp;
&lt;input name=&quot;del_1&quot; type=&quot;checkbox&quot; /&gt;
&lt;input name=&quot;id_1&quot; type=&quot;hidden&quot; value=&quot;117&quot; /&gt;
&lt;input name=&quot;del_2&quot; type=&quot;checkbox&quot; /&gt;
&lt;input name=&quot;id_2&quot; type=&quot;hidden&quot; value=&quot;95&quot; /&gt;</pre>
<p>Note each field had its name attached with a _row number so you will see an id_1 as a field name.  After this form is submitted you can use the below php code to get the values dynamically.</p>
<p><code class="php"><br />
// Check for item delete<br />
if ((isset($_POST['delete'])) or (isset($_POST['delete_x']))){<br />
for ($i=0; $i&lt;=$totrecs; $i++)<br />
{<br />
$tdel=$_POST['del_'.$i];<br />
$tid=$_POST['id_'.$i];<br />
// Another way to do this is this way<br />
// $tempvar="id_".$i;<br />
// $tid=$_POST[${$tempvar}];<br />
if ($tdel=="on")<br />
{<br />
// Delete Item, the item ID is $tid<br />
}<br />
} // Loop<br />
} // End Post Check<br />
</code></p>
<p><strong>Template Lite And Dynamic Variables</strong><br />
Form Data grid is also the reason I used dynamic variables in templates.  Once I have edited a data grid I need to set values in the grid, select drop downs and, check radio or check boxes.   There is some extra steps you need to do to use them and it also depends on how you pass your data to template lite.  The following is an example showing a more complex use of variable variables.</p>
<pre class="smarty"><span style="color: #D36900;">&#123;</span><a href="http://smarty.php.net/foreach"><span style="color: #0600FF;">foreach</span></a> <span style="color: #6A0A0A;">key</span>=key2 <span style="color: #6A0A0A;">value</span>=item2 <span style="color: #6A0A0A;">from</span>=$jetarray <span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span> <a href="http://smarty.php.net/assign"><span style="color: #0600FF;">assign</span></a> var=<span style="color: #ff0000;">&quot;dummyvar1&quot;</span> <span style="color: #6A0A0A;">value</span>=<span style="color: #ff0000;">&quot;`$item2.jetski_id`_bookid&quot;</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span> <a href="http://smarty.php.net/assign"><span style="color: #0600FF;">assign</span></a> var=<span style="color: #ff0000;">&quot;dummyvar2&quot;</span> <span style="color: #6A0A0A;">value</span>=<span style="color: #ff0000;">&quot;`$item2.jetski_id`_owner&quot;</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span> <a href="http://smarty.php.net/assign"><span style="color: #0600FF;">assign</span></a> var=<span style="color: #ff0000;">&quot;cellcolor&quot;</span> <span style="color: #6A0A0A;">value</span>=<span style="color: #ff0000;">&quot;`$item2.jetski_id`_color&quot;</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span> <a href="http://smarty.php.net/assign"><span style="color: #0600FF;">assign</span></a> var=<span style="color: #ff0000;">&quot;dummyvar3&quot;</span> <span style="color: #6A0A0A;">value</span>=<span style="color: #ff0000;">&quot;`$item2.jetski_id`&quot;</span><span style="color: #D36900;">&#125;</span>
&nbsp;
 <span style="color: #D36900;">&#123;</span><a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> $item<span style="color: #D36900;">&#91;</span>$dummyvar1<span style="color: #D36900;">&#93;</span>!=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #D36900;">&#125;</span>
   <span style="color: #D36900;">&#123;</span><a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> $session.<span style="color: #006600;">myid</span> == $item<span style="color: #D36900;">&#91;</span>$dummyvar2<span style="color: #D36900;">&#93;</span><span style="color: #D36900;">&#125;</span>
&lt;input name=&quot;jetid_<span style="color: #D36900;">&#123;</span>$item2.<span style="color: #006600;">jetski_id</span><span style="color: #D36900;">&#125;</span>_<span style="color: #D36900;">&#123;</span>$key<span style="color: #D36900;">&#125;</span>&quot; type=&quot;hidden&quot;
 value=&quot;<span style="color: #D36900;">&#123;</span>$item2.<span style="color: #006600;">jetski_id</span><span style="color: #D36900;">&#125;</span>&quot; /&gt;
   <span style="color: #D36900;">&#123;</span>/if<span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span>/if<span style="color: #D36900;">&#125;</span>
&nbsp;
 <span style="color: #D36900;">&#123;</span>/foreach<span style="color: #D36900;">&#125;</span></pre>
<p>Note we assigned a variable  $dummyvar1 with the value $item2.jetski_id and appended _bookid to that variable name.  Jetski number 1 turns into 1_bookid. After that we pull the value out of the array $item[$dummyvar1]  so what we are actually doing is viewing $item['1_bookid'].</p>
<p>While there are some other uses for dynamic variables these are how I most recently have used them.  If it helps someone other than myself, cool.  Otherwise this is a place I have my own personal reference library.</p>
]]></description>
			<content:encoded><![CDATA[<p>There is one programing concept that always hurts my head, and  that is the variable variables or dynamic variables.   What dynamic let you do is access data from the value of the a variable you are viewing.  (See I told you it would hurt your head)</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$b</span> =<span style="color: #cc66cc;">20</span>;  <span style="color: #808080; font-style: italic;">// set the value of b</span>
<span style="color: #0000ff;">$c</span>=<span style="color: #ff0000;">&quot;b&quot;</span>;  <span style="color: #808080; font-style: italic;">// set c to the name of the variable you want to view</span>
<span style="color: #0000ff;">$d</span>=$<span style="color: #66cc66;">&#123;</span><span style="color: #0000ff;">$c</span><span style="color: #66cc66;">&#125;</span>; <span style="color: #808080; font-style: italic;">// the variable variable  $d is now equal to 20</span>
&nbsp;</pre>
<p>Many of you are probably asking yourself, " OK I understand that , but why do I need to do that?"<br />
The number one place I use this, is in a web grid form. Any place you need to update/or delete data in that grid.  Below is an example of what a grid of data may look like:</p>
<p style="text-align: center;"><a href="http://blog.oznet.com/wp-content/uploads/2008/04/datagrid.jpg"><img class="size-full wp-image-5" title="datagrid" src="http://blog.oznet.com/wp-content/uploads/2008/04/datagrid.jpg" alt="Data Grid" width="400" height="222" /></a></p>
<p style="text-align: left;">The issues you face in the above grid is how do I delete multiple items and change multiple elements of data in grid once it is submitted.  The solution is you assign each field a row number and add that to the field name.</p>
<p style="text-align: left;">Example:</p>
<p style="text-align: left;">
<p style="text-align: left;">
<pre>&nbsp;
&lt;input name=&quot;del_1&quot; type=&quot;checkbox&quot; /&gt;
&lt;input name=&quot;id_1&quot; type=&quot;hidden&quot; value=&quot;117&quot; /&gt;
&lt;input name=&quot;del_2&quot; type=&quot;checkbox&quot; /&gt;
&lt;input name=&quot;id_2&quot; type=&quot;hidden&quot; value=&quot;95&quot; /&gt;</pre>
<p>Note each field had its name attached with a _row number so you will see an id_1 as a field name.  After this form is submitted you can use the below php code to get the values dynamically.</p>
<p><code class="php"><br />
// Check for item delete<br />
if ((isset($_POST['delete'])) or (isset($_POST['delete_x']))){<br />
for ($i=0; $i&lt;=$totrecs; $i++)<br />
{<br />
$tdel=$_POST['del_'.$i];<br />
$tid=$_POST['id_'.$i];<br />
// Another way to do this is this way<br />
// $tempvar="id_".$i;<br />
// $tid=$_POST[${$tempvar}];<br />
if ($tdel=="on")<br />
{<br />
// Delete Item, the item ID is $tid<br />
}<br />
} // Loop<br />
} // End Post Check<br />
</code></p>
<p><strong>Template Lite And Dynamic Variables</strong><br />
Form Data grid is also the reason I used dynamic variables in templates.  Once I have edited a data grid I need to set values in the grid, select drop downs and, check radio or check boxes.   There is some extra steps you need to do to use them and it also depends on how you pass your data to template lite.  The following is an example showing a more complex use of variable variables.</p>
<pre class="smarty"><span style="color: #D36900;">&#123;</span><a href="http://smarty.php.net/foreach"><span style="color: #0600FF;">foreach</span></a> <span style="color: #6A0A0A;">key</span>=key2 <span style="color: #6A0A0A;">value</span>=item2 <span style="color: #6A0A0A;">from</span>=$jetarray <span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span> <a href="http://smarty.php.net/assign"><span style="color: #0600FF;">assign</span></a> var=<span style="color: #ff0000;">&quot;dummyvar1&quot;</span> <span style="color: #6A0A0A;">value</span>=<span style="color: #ff0000;">&quot;`$item2.jetski_id`_bookid&quot;</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span> <a href="http://smarty.php.net/assign"><span style="color: #0600FF;">assign</span></a> var=<span style="color: #ff0000;">&quot;dummyvar2&quot;</span> <span style="color: #6A0A0A;">value</span>=<span style="color: #ff0000;">&quot;`$item2.jetski_id`_owner&quot;</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span> <a href="http://smarty.php.net/assign"><span style="color: #0600FF;">assign</span></a> var=<span style="color: #ff0000;">&quot;cellcolor&quot;</span> <span style="color: #6A0A0A;">value</span>=<span style="color: #ff0000;">&quot;`$item2.jetski_id`_color&quot;</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span> <a href="http://smarty.php.net/assign"><span style="color: #0600FF;">assign</span></a> var=<span style="color: #ff0000;">&quot;dummyvar3&quot;</span> <span style="color: #6A0A0A;">value</span>=<span style="color: #ff0000;">&quot;`$item2.jetski_id`&quot;</span><span style="color: #D36900;">&#125;</span>
&nbsp;
 <span style="color: #D36900;">&#123;</span><a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> $item<span style="color: #D36900;">&#91;</span>$dummyvar1<span style="color: #D36900;">&#93;</span>!=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #D36900;">&#125;</span>
   <span style="color: #D36900;">&#123;</span><a href="http://smarty.php.net/if"><span style="color: #0600FF;">if</span></a> $session.<span style="color: #006600;">myid</span> == $item<span style="color: #D36900;">&#91;</span>$dummyvar2<span style="color: #D36900;">&#93;</span><span style="color: #D36900;">&#125;</span>
&lt;input name=&quot;jetid_<span style="color: #D36900;">&#123;</span>$item2.<span style="color: #006600;">jetski_id</span><span style="color: #D36900;">&#125;</span>_<span style="color: #D36900;">&#123;</span>$key<span style="color: #D36900;">&#125;</span>&quot; type=&quot;hidden&quot;
 value=&quot;<span style="color: #D36900;">&#123;</span>$item2.<span style="color: #006600;">jetski_id</span><span style="color: #D36900;">&#125;</span>&quot; /&gt;
   <span style="color: #D36900;">&#123;</span>/if<span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span>/if<span style="color: #D36900;">&#125;</span>
&nbsp;
 <span style="color: #D36900;">&#123;</span>/foreach<span style="color: #D36900;">&#125;</span></pre>
<p>Note we assigned a variable  $dummyvar1 with the value $item2.jetski_id and appended _bookid to that variable name.  Jetski number 1 turns into 1_bookid. After that we pull the value out of the array $item[$dummyvar1]  so what we are actually doing is viewing $item['1_bookid'].</p>
<p>While there are some other uses for dynamic variables these are how I most recently have used them.  If it helps someone other than myself, cool.  Otherwise this is a place I have my own personal reference library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bswebdev.com/2008/05/variable-variables-and-template-lite/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Template Lite Modifiers</title>
		<link>http://www.bswebdev.com/2008/04/template-lite-modifiers/</link>
		<comments>http://www.bswebdev.com/2008/04/template-lite-modifiers/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 06:16:20 +0000</pubDate>
		<dc:creator>tarnus</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Template Lite]]></category>

		<guid isPermaLink="false">http://blog.oznet.com/?p=3</guid>
		<description><![CDATA[<p>One of the greatest tools I have in my library set is <a title="Template Lite" href="http://templatelite.sourceforge.net/" target="_blank">Template Lite </a>.   Template lite is a light-weight version of another template engine known as <a title="Smarty" href="http://www.smarty.net" target="_blank">Smarty. </a> Once you start using template lite you will be pleasantly surprised by how powerful yet modular it is.</p>
<p>My whole point of this blog is to talk about modifiers.   A modifier enables you to pass some php modifying code into a template lite variable.</p>
<p style="padding-left: 30px;"><strong>Example:</strong>
</p>
<p><code class="php"><br />
{$mytlitevariable|ucfirst }<br />
//This would capitalize the first letter of the variable. </code><br />
<strong>What doesn't work</strong></p>
<p>It is important to note that you cannot necessarily use this on all modify type php functions.  Some php functions do not pass the main variable into the first option.</p>
<p>Using <span class="methodname"><strong>str_replace</strong> would not work as the passed variable is the third option in the command. </span><code class="php">{$mytlitevariable|str_replace:black:brown</span> }<br />
//is the equivalent to<br />
str_replace($mytlitevariable,"black","brown")<br />
//which will not work.   You will have to  use it  via php:<br />
{php} echo str_replace("black","brown",$mytlitevariable)  {/php}</code></p>
<p><strong>Modifiers Stacking</strong></p>
<p>Modifier stacking allows you to make multiple changes to a variable by passing multiple modifiers to the template lite variable.</p>
<p style="padding-left: 30px;">Example: {$myvar|ucfirst|truncate:40:"..."}</p>
<p><strong>Creating your own Modifiers</strong></p>
<p>Don't be afraid to create your own modifiers.  When ever I run into something that I can't do I add it into template lite.<br />
<code class=php">//Example: This is the source code for the indent modifier.<br />
//Once you create the modifier and save it in the plugins folder with the name<br />
//modifier.indent.php.<br />
{$myvar|indent}<br />
//Note there are 2 extra arguments you can use with it as well.</code></p>
<p><code class="php">function tpl_modifier_indent($string,$chars=4,$char=" ")<br />
{<br />
return preg_replace('!^!m',str_repeat($char,$chars),$string);<br />
}</code><br />
This is the start of my experimentation with blogs.  I am constantly forgetting how to do things with template lite and other things.   I plan on adding these tips and tricks to my blog so I have one place to search for the info.  Feel free to comment as I realize I don't know it all but am willing to share my experiences along the way.</p>
<p style="padding-left: 30px;">
<p style="padding-left: 30px;">
<p style="padding-left: 30px;">
<p style="padding-left: 30px;">
]]></description>
			<content:encoded><![CDATA[<p>One of the greatest tools I have in my library set is <a title="Template Lite" href="http://templatelite.sourceforge.net/" target="_blank">Template Lite </a>.   Template lite is a light-weight version of another template engine known as <a title="Smarty" href="http://www.smarty.net" target="_blank">Smarty. </a> Once you start using template lite you will be pleasantly surprised by how powerful yet modular it is.</p>
<p>My whole point of this blog is to talk about modifiers.   A modifier enables you to pass some php modifying code into a template lite variable.</p>
<p style="padding-left: 30px;"><strong>Example:</strong>
</p>
<p><code class="php"><br />
{$mytlitevariable|ucfirst }<br />
//This would capitalize the first letter of the variable. </code><br />
<strong>What doesn't work</strong></p>
<p>It is important to note that you cannot necessarily use this on all modify type php functions.  Some php functions do not pass the main variable into the first option.</p>
<p>Using <span class="methodname"><strong>str_replace</strong> would not work as the passed variable is the third option in the command. </span><code class="php">{$mytlitevariable|str_replace:black:brown</span> }<br />
//is the equivalent to<br />
str_replace($mytlitevariable,"black","brown")<br />
//which will not work.   You will have to  use it  via php:<br />
{php} echo str_replace("black","brown",$mytlitevariable)  {/php}</code></p>
<p><strong>Modifiers Stacking</strong></p>
<p>Modifier stacking allows you to make multiple changes to a variable by passing multiple modifiers to the template lite variable.</p>
<p style="padding-left: 30px;">Example: {$myvar|ucfirst|truncate:40:"..."}</p>
<p><strong>Creating your own Modifiers</strong></p>
<p>Don't be afraid to create your own modifiers.  When ever I run into something that I can't do I add it into template lite.<br />
<code class=php">//Example: This is the source code for the indent modifier.<br />
//Once you create the modifier and save it in the plugins folder with the name<br />
//modifier.indent.php.<br />
{$myvar|indent}<br />
//Note there are 2 extra arguments you can use with it as well.</code></p>
<p><code class="php">function tpl_modifier_indent($string,$chars=4,$char=" ")<br />
{<br />
return preg_replace('!^!m',str_repeat($char,$chars),$string);<br />
}</code><br />
This is the start of my experimentation with blogs.  I am constantly forgetting how to do things with template lite and other things.   I plan on adding these tips and tricks to my blog so I have one place to search for the info.  Feel free to comment as I realize I don't know it all but am willing to share my experiences along the way.</p>
<p style="padding-left: 30px;">
<p style="padding-left: 30px;">
<p style="padding-left: 30px;">
<p style="padding-left: 30px;">
]]></content:encoded>
			<wfw:commentRss>http://www.bswebdev.com/2008/04/template-lite-modifiers/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
