<?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>BRADINO</title>
	<atom:link href="http://www.bradino.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bradino.com</link>
	<description>Just another Wordpress blog</description>
	<lastBuildDate>Wed, 09 Nov 2011 20:09:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Pass Extra Parameters to JavaScript Callback Function</title>
		<link>http://www.bradino.com/javascript/pass-extra-parameters-to-javascript-callback-function/</link>
		<comments>http://www.bradino.com/javascript/pass-extra-parameters-to-javascript-callback-function/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 20:49:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4898</guid>
		<description><![CDATA[Here is a simple example of a function that takes a callback function as a parameter. &#160; query.send&#40;handleQueryResponse&#41;; &#160; function handleQueryResponse&#40;response&#41;&#123; &#160; alert&#40;'Processing...'&#41;; &#160; &#125; If you wanted to pass extra variables to the callback function, you can do it like this. &#160; var param1 = 'something'; &#160; var param2 ='something else'; &#160; query.send&#40;function&#40;response&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple example of a function that takes a callback function as a parameter.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
query.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>handleQueryResponse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> handleQueryResponse<span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Processing...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you wanted to pass extra variables to the callback function, you can do it like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> param1 <span style="color: #339933;">=</span> <span style="color: #3366CC;">'something'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> param2 <span style="color: #339933;">=</span><span style="color: #3366CC;">'something else'</span><span style="color: #339933;">;</span>
&nbsp;
query.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> handleQueryResponse<span style="color: #009900;">&#40;</span>response<span style="color: #339933;">,</span> param1<span style="color: #339933;">,</span> param2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> handleQueryResponse<span style="color: #009900;">&#40;</span>response<span style="color: #339933;">,</span>param1<span style="color: #339933;">,</span>param2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Processing...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>param1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>param2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/pass-extra-parameters-to-javascript-callback-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL Multiple Query Parameters Encoded with HTML Entities</title>
		<link>http://www.bradino.com/php/url-multiple-query-parameters-encoded-with-html-entities/</link>
		<comments>http://www.bradino.com/php/url-multiple-query-parameters-encoded-with-html-entities/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 21:10:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4888</guid>
		<description><![CDATA[I came across a situation where a URL with multiple query parameters was encoded using htmlentities() and PHP was not recognizing the query parameters using $_GET. A common case for encoding urls using htmlentities() is to use them inside XML documents. So a url with multiple query parameters, encoded using htmlentities() would look like this: [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a situation where a URL with multiple query parameters was encoded using htmlentities() and PHP was not recognizing the query parameters using $_GET. A common case for encoding urls using htmlentities() is to use them inside XML documents.</p>
<p>So a url with multiple query parameters, encoded using htmlentities() would look like this:</p>
<p>http://www.bradino.com/?color=white&amp;size=medium&amp;quantity=3</p>
<p>and when that url is accessed the second and third query parameters are not recognized because instead of separating the subsequent variables with an &#038; that character gets converted into &amp;amp;. I could not find a good way to resolve this, so basically I just encoded the query string back to normal using html_entity_decode() and then slammed the parameters back into the $_GET array using parse_str().</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">html_entity_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There must be a better way! Anyone come across this before?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/php/url-multiple-query-parameters-encoded-with-html-entities/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Screen Scraping Class</title>
		<link>http://www.bradino.com/php/php-screen-scraping-class/</link>
		<comments>http://www.bradino.com/php/php-screen-scraping-class/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 01:04:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Screen Scraping]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4882</guid>
		<description><![CDATA[After some positive feedback I have decided to continue to develop the PHP Screen Scraping class. This post will server as the permanent home for the class. Download PHP Screen Scraping Class Updates 20009-07-30 Added setHeader() function]]></description>
			<content:encoded><![CDATA[<p>After some positive feedback I have decided to continue to develop the PHP Screen Scraping class. This post will server as the permanent home for the class.</p>
<p><a href="http://www.bradino.com/downloads/cScrape.txt" target="blank">Download PHP Screen Scraping Class</a></p>
<p><strong>Updates</strong></p>
<p> 20009-07-30 Added setHeader() function</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/php/php-screen-scraping-class/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CakePHP Missing Database Table Error</title>
		<link>http://www.bradino.com/php/cakephp-missing-database-table/</link>
		<comments>http://www.bradino.com/php/cakephp-missing-database-table/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 01:07:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4875</guid>
		<description><![CDATA[I am baking a new project management application at work and added a couple new tables to the database today. When I went into the console to bake the new models, they were not in the list&#8230; php /path/cake/console/cake.php bake all -app /path/app/ So I manually typed in the model name and I got a [...]]]></description>
			<content:encoded><![CDATA[<p>I am baking a new project management application at work and added a couple new tables to the database today. When I went into the console to bake the new models, they were not in the list&#8230;</p>
<p><strong>php /path/cake/console/cake.php bake all -app /path/app/</strong></p>
<p>So I manually typed in the model name and I got a missing database table for model error. I checked and double-checked and the database table was named properly. Turns out that some files inside the <strong>/app/tmp/cache/</strong> folder were causing Cake not to recognize that I had added new tables to my database. Once I deleted the cache files cake instantly recognized my new database tables and I was baking away!</p>
<p><strong>rm -Rf /path/app/tmp/cache/cake*</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/php/cakephp-missing-database-table/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL Query Cache</title>
		<link>http://www.bradino.com/mysql/query-cache/</link>
		<comments>http://www.bradino.com/mysql/query-cache/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 00:20:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4867</guid>
		<description><![CDATA[According to MySQL.com the query cache stores the text of a SELECT statement together with the corresponding result that was sent to the client. If an identical statement is received later, the server retrieves the results from the query cache rather than parsing and executing the statement again. The query cache is shared among sessions, [...]]]></description>
			<content:encoded><![CDATA[<p>According to <a href="http://dev.mysql.com/doc/refman/5.1/en/query-cache.html" target="blank" rel="nofollow">MySQL.com</a> the query cache stores the text of a SELECT statement together with the corresponding result that was sent to the client. If an identical statement is received later, the server retrieves the results from the query cache rather than parsing and executing the statement again. The query cache is shared among sessions, so a result set generated by one client can be sent in response to the same query issued by another client. </p>
<p>Purely hypothetical example:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">`name`</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`beers`</span> <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008000;">`favorite`</span> <span style="color: #CC0099;">=</span> <span style="color: #9900FF; font-weight: bold;">true</span></pre></div></div>

<p>To force the database NOT to give you a cached result simply add <strong>SQL_NO_CACHE</strong> to the query:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #990099; font-weight: bold;">SQL_NO_CACHE</span> <span style="color: #008000;">`name`</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`beers`</span> <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008000;">`favorite`</span> <span style="color: #CC0099;">=</span> <span style="color: #9900FF; font-weight: bold;">true</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/mysql/query-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Count Email Address Domains</title>
		<link>http://www.bradino.com/mysql/count-email-address-domains/</link>
		<comments>http://www.bradino.com/mysql/count-email-address-domains/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 01:03:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4861</guid>
		<description><![CDATA[A quick tidbit I came up with today to count email addresses in a mysql database table grouping them by domain. So say for example you have a large list of subscribers and you want to see the breakdown of people who use Hotmail, Yahoo, Gmail, etc. SELECT COUNT&#40; SUBSTRING_INDEX&#40; `email` , '@', -1 &#41; [...]]]></description>
			<content:encoded><![CDATA[<p>A quick tidbit I came up with today to count email addresses in a mysql database table grouping them by domain. So say for example you have a large list of subscribers and you want to see the breakdown of people who use Hotmail, Yahoo, Gmail, etc.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">COUNT</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">SUBSTRING_INDEX</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">`email`</span> <span style="color: #000033;">,</span> <span style="color: #008000;">'@'</span><span style="color: #000033;">,</span> <span style="color: #CC0099;">-</span><span style="color: #008080;">1</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #008000;">`count`</span> <span style="color: #000033;">,</span> 
<span style="color: #000099;">SUBSTRING_INDEX</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">`email`</span> <span style="color: #000033;">,</span> <span style="color: #008000;">'@'</span><span style="color: #000033;">,</span> <span style="color: #CC0099;">-</span><span style="color: #008080;">1</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #008000;">`domain`</span>
<span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`subscribers`</span> <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008000;">`email`</span> <span style="color: #CC0099;">!=</span> <span style="color: #008000;">''</span> 
<span style="color: #990099; font-weight: bold;">GROUP BY</span> <span style="color: #008000;">`domain`</span>
<span style="color: #990099; font-weight: bold;">ORDER BY</span> <span style="color: #008000;">`count`</span> <span style="color: #990099; font-weight: bold;">DESC</span></pre></div></div>

<p>This sql statement assumes that the table is called &#8216;subscribers&#8217; and the column containing the email addresses is &#8216;email&#8217;. Change these two values to match your table name and email address column name. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/mysql/count-email-address-domains/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Screen Scraping Twitter</title>
		<link>http://www.bradino.com/php/screen-scraping-twitter/</link>
		<comments>http://www.bradino.com/php/screen-scraping-twitter/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 17:20:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Screen Scraping]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4845</guid>
		<description><![CDATA[I got an email today asking for help to scrape Twitter. In particular, to be able to login. So I am going to show everyone, NOT to encourage anyone to violate Twitters terms of use but as an educational blog post about how PHP and cURL can be used to post variables and store cookies. [...]]]></description>
			<content:encoded><![CDATA[<p>I got an email today asking for help to scrape Twitter. In particular, to be able to login. So I am going to show everyone, NOT to encourage anyone to violate Twitters terms of use but as an educational blog post about how PHP and cURL can be used to post variables and store cookies.</p>
<p>Again, I am using the cScrape class I wrote, which you can <a href="http://www.bradino.com/downloads/cScrape.txt">download</a>. </p>
<p><strong>Step 1</strong><br />
First go to twitter.com and look at the source code of the login to get the form field names and the form post location. You will see that the form posts to https://twitter.com/session and the username and password fields are session[username_or_email] and session[password] respectively.</p>
<p><strong>Step 2</strong><br />
Now you are ready to login. So using the fetch function in the Scrape class you create an associative array to contain the form values you want to post. The other thing you will need to do is uncomment the lines for CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR. Cookies will be required to stay logged in and scrape around. The paths to the cookie files need to be writable by your app. Also you will need to uncomment the line about CURLOPT_FOLLOWLOCATION.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session[username_or_email]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;bradino&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'session[password]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;secret&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$scrape</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https://twitter.com/sessions'</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Step 1.5</strong><br />
Oops that didn&#8217;t work. All I got back was <em>403 Forbidden: The server understood the request, but is refusing to fulfill it</em>. Ahhh I see another variable called authenticity_token I bet Twitter was looking for that. So let&#8217;s back up and first hit twitter.com to get the authenticity_token variable, and then make the login post request with that variable included in our array of parameters.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$scrape</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https://twitter.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session[username_or_email]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;bradino&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'session[password]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;secret&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'authenticity_token'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$scrape</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchBetween</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name=&quot;authenticity_token&quot; type=&quot;hidden&quot; value=&quot;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span><span style="color: #000088;">$scrape</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$scrape</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https://twitter.com/sessions'</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$scrape</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #339933;">;</span></pre></div></div>

<p>So that&#8217;s basically it. Now you are logged in and can scrape around and request other pages as you normally would. Sorry it wasn&#8217;t a longer post. I really do enjoy this kind of stuff so if anyone has a request, hit me up.</p>
<p><strong>Errors?</strong><br />
1) Make sure that you are properly parsing the token variable<br />
2) Make sure that you uncommented the lines about CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR, those options need to be enabled and be sure the path set is writable by your application<br />
3) Make sure that the path to the cookie file is writable and that it is getting data written to it<br />
4) If you get a message about being redirected you need to uncomment the line about CURLOPT_FOLLOWLOCATION, that option needs to be enabled true</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/php/screen-scraping-twitter/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Zipcodes in CSV Generation</title>
		<link>http://www.bradino.com/php/zipcodes-in-csv-generation/</link>
		<comments>http://www.bradino.com/php/zipcodes-in-csv-generation/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 22:30:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4839</guid>
		<description><![CDATA[When exporting to CSV format, then opening in a spreadsheet program like Excel zipcodes that start with a zero or zeroes have the preceding zeros stripped off. Obviously it is because the spreadsheet sees that column as integers and preceding zeros in integers are useless. A quick and dirty trick to force Excel (hopefully you [...]]]></description>
			<content:encoded><![CDATA[<p>When exporting to CSV format, then opening in a spreadsheet program like Excel zipcodes that start with a zero or zeroes have the preceding zeros stripped off. Obviously it is because the spreadsheet sees that column as integers and preceding zeros in integers are useless.</p>
<p>A quick and dirty trick to force Excel (hopefully you are using OpenOffice) to display the full zipcode, we wrap it in double quotes and put an equal sign in front of it, to force it to be a string like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$zipcode</span> <span style="color: #339933;">=</span> <span style="color: #208080;">00123</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$zipcode</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">;</span></pre></div></div>

<p>So if you are doing the straight query to CSV export, using the <b>fputcsv</b> function it would look something like this. Basically just overwrite the value in the row and then continue along.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'zipcode'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'zipcode'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">fputcsv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/php/zipcodes-in-csv-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculate Age using Date Field</title>
		<link>http://www.bradino.com/mysql/calculate-age-using-date-field/</link>
		<comments>http://www.bradino.com/mysql/calculate-age-using-date-field/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 00:45:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4833</guid>
		<description><![CDATA[So if you have a database table that has DOB borthdays as date fields, this is an easy way to query that table based on age parameters. The following examples assume that the date of birth date field is dob and the table name is people. Find people who are 30 years old SELECT DATE_FORMAT&#40; [...]]]></description>
			<content:encoded><![CDATA[<p>So if you have a database table that has DOB borthdays as date fields, this is an easy way to query that table based on age parameters. The following examples assume that the date of birth date field is dob and the table name is people.</p>
<p>Find people who are 30 years old</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">DATE_FORMAT</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">FROM_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">TO_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">now</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">-</span> <span style="color: #000099;">TO_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">`dob`</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #000033;">,</span> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>Y'</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">+</span><span style="color: #008080;">0</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #008000;">`age`</span>
<span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`people`</span> <span style="color: #990099; font-weight: bold;">HAVING</span> <span style="color: #008000;">`age`</span> <span style="color: #CC0099;">=</span> <span style="color: #008080;">30</span></pre></div></div>

<p>Find people who are 31-42 years old</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">DATE_FORMAT</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">FROM_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">TO_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">now</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">-</span> <span style="color: #000099;">TO_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">`dob`</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #000033;">,</span> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>Y'</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">+</span><span style="color: #008080;">0</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #008000;">`age`</span>
<span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`people`</span> <span style="color: #990099; font-weight: bold;">HAVING</span> <span style="color: #008000;">`age`</span> <span style="color: #CC0099;">&gt;=</span> <span style="color: #008080;">31</span> <span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #008000;">`age`</span> <span style="color: #CC0099;">&lt;=</span> <span style="color: #008080;">42</span></pre></div></div>

<p>Find oldest person</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">MAX</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">DATE_FORMAT</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">FROM_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">TO_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">now</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">-</span> <span style="color: #000099;">TO_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">`dob`</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #000033;">,</span> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>Y'</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">+</span><span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #008000;">`age`</span>
<span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`people`</span></pre></div></div>

<p>Find youngest person</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">MIN</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">DATE_FORMAT</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">FROM_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">TO_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #000099;">now</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">-</span> <span style="color: #000099;">TO_DAYS</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008000;">`dob`</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #000033;">,</span> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>Y'</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">+</span><span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #008000;">`age`</span>
<span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`people`</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/mysql/calculate-age-using-date-field/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replace Listmenu with Textfield</title>
		<link>http://www.bradino.com/javascript/replace-listmenu-with-textfield/</link>
		<comments>http://www.bradino.com/javascript/replace-listmenu-with-textfield/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 00:36:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4819</guid>
		<description><![CDATA[Say you have a dropdown form field where you ask the user how they heard about you. You have numerous options and also an other field where if they selected other, then they enter the value in a text field. This is a cleaner alternative where if the user selects Other, then the dropdown turns [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have a dropdown form field where you ask the user how they heard about you. You have numerous options and also an other field where if they selected other, then they enter the value in a text field. This is a cleaner alternative where if the user selects Other, then the dropdown turns into a textfield of the same name, so that your post routine, grooming, validation, writing to DB etc all works seamlessly. This example uses prototype JS library.</p>
<p>Here is a working example:</p>
<p><em>How did you hear about BRADINO?<em></p>
<select id="how-heard" name="how-heard" onchange="overrideListmenu('how-heard');">
<option value="Select">Select</option>
<option value="Google">Google</option>
<option value="Google">Yahoo</option>
<option value="Google">MSN</option>
<option value="Other">Other</option>
</select>
<p>All you have to do is have an dropdown option for Other and then add call the function onchange:</p>
<p><strong>onchange=&#8221;overrideListmenu(&#8216;how-heard&#8217;);&#8221;</strong></p>
<p>Here is the javascript function that uses <strong>Prototype</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> overrideListmenu<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$F<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'Other'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		Element.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'&lt;input name=&quot;'</span><span style="color: #339933;">+</span>field<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; id=&quot;'</span><span style="color: #339933;">+</span>field<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; type=&quot;text&quot; value=&quot;&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here is the javascript function that uses <strong>jQuery</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> overrideListmenu<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>field<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'Other'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>field<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;input name=&quot;'</span><span style="color: #339933;">+</span>field<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; id=&quot;'</span><span style="color: #339933;">+</span>field<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; type=&quot;text&quot; value=&quot;&quot;&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>field<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/replace-listmenu-with-textfield/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

