<?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>SkeyMedia &#187; Programming</title>
	<atom:link href="http://skeymedia.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://skeymedia.com</link>
	<description>Blogging about Web Development and Website Management &#38; Monetization</description>
	<lastBuildDate>Sun, 20 Sep 2009 23:18:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>IE6 AJAX hang on readyState 3</title>
		<link>http://skeymedia.com/ie6-ajax-hang-on-readystate-3/</link>
		<comments>http://skeymedia.com/ie6-ajax-hang-on-readystate-3/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 18:10:01 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ie6]]></category>

		<guid isPermaLink="false">http://skeymedia.com/ie6-ajax-hang-on-readystate-3/</guid>
		<description><![CDATA[I recently ran into a problem that took me a few days to find a work around for. Running a basic AJAX POST, IE6 would hang up on readyState 3 for 200 seconds, throw an &#8220;Unspecified Error&#8220;, and then finally perform the action. Having a user wait 200 seconds for the IE6 timeout to come [...]]]></description>
			<content:encoded><![CDATA[<p>I recently ran into a problem that took me a few days to find a work around for.  Running a basic AJAX POST, IE6 would hang up on readyState 3 for 200 seconds, throw an &#8220;<em>Unspecified Error</em>&#8220;, and then finally perform the action.   Having a user wait 200 seconds for the IE6 timeout to come into effect is simply not a solution.  All other browsers I tested, including IE7, were not having this problem.</p>
<p>I read on the web that this may come from SSL or from compression on the webserver.   I bypassed our SSL check entirely, and it still happened.   I did not mess with the servers for http compression though.  To me, that is NOT an option to disable.   Bandwidth costs would be too much to even consider this a viable solution.</p>
<p>So, I returned to the programming aspect of it.  There has to be a code fix somewhere.</p>
<p>Long story short, IE6 doesn&#8217;t handle connection closures properly.   A typical request looks something like:</p>
<p><pre><code>
function doajax() {
var url = &quot;/script.php&quot;;
var params = &quot;x=123&amp;y=456&quot;;

//add timestamp to pass a unique param each time to prevent ie caching the ajax object
timestamp = new Date();
tim1 = (timestamp.getTime());
sec1 = timestamp.getSeconds();
ms1 = timestamp.getMilliseconds();
thetime = tim1+sec1+ms1;

params += &quot;&amp;rand=&quot;+thetime

xmlHttp.open(&#039;POST&#039;,url,true);&nbsp;&nbsp;
xmlHttp.onreadystatechange = alertContents;&nbsp;&nbsp;
xmlHttp.setRequestHeader(&quot;Content-type&quot;, &quot;application/x-www-form-urlencoded&quot;);
xmlHttp.setRequestHeader(&#039;If-Modified-Since&#039;,&#039;Tue, 04 Apr 2006 00:00:00 GMT&#039;);&nbsp;&nbsp;//some date in the past
xmlHttp.setRequestHeader(&quot;Content-length&quot;, params.length);
xmlHttp.setRequestHeader(&quot;Connection&quot;, &quot;close&quot;);
}
xmlHttp.send(params);
</code></pre></p>
<p>The line in question here is<br />
<pre><code>
xmlHttp.setRequestHeader(&quot;Connection&quot;, &quot;close&quot;);
</code></pre></p>
<p>Since this header is effectively applied for each readyState, it ends up hanging up on readyState 3.</p>
<p><strong>The easy fix:</strong><br />
Target ie6 (and other old browsers) to not close the connection.</p>
<p>change the above snippet to:<br />
<pre><code>
if(!document.all) {
&nbsp;&nbsp;xmlHttp.setRequestHeader(&quot;Connection&quot;, &quot;close&quot;);
}
</code></pre></p>
<p>I&#8217;m not 100% sure of the implications involved in NOT closing the connection, but I haven&#8217;t seen any performance impact, and this cleared up the bug right away.  No JS errors, and no 200 second waiting.  Give it a try and let me know if it works for you as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/ie6-ajax-hang-on-readystate-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Freelance Programming Feedback</title>
		<link>http://skeymedia.com/freelance-programming-feedback/</link>
		<comments>http://skeymedia.com/freelance-programming-feedback/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 05:11:45 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[feedback]]></category>

		<guid isPermaLink="false">http://skeymedia.com/freelance-programming-feedback/</guid>
		<description><![CDATA[This post contains comments from people whom I&#8217;ve done custom work for in the WordPress, vBulletin, and vBSEO worlds. I&#8217;ve asked those that I&#8217;ve worked with before to leave a few words here about my quality of work. If I&#8217;ve done work for you, please leave a few words so others who are considering working [...]]]></description>
			<content:encoded><![CDATA[<p>This post contains comments from people whom I&#8217;ve done custom work for in the WordPress, vBulletin, and vBSEO worlds.   I&#8217;ve asked those that I&#8217;ve worked with before to leave a few words here about my quality of work.   </p>
<p>If I&#8217;ve done work for you, please leave a few words so others who are considering working with me know that I&#8217;m legit and can deliver as promised.</p>
<p>Thanks</p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/freelance-programming-feedback/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WordPress Permalinks on IIS with ISAPI_Rewrite</title>
		<link>http://skeymedia.com/permalinks-iis-isapi/</link>
		<comments>http://skeymedia.com/permalinks-iis-isapi/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 16:50:46 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[ISAPI Rewrite]]></category>
		<category><![CDATA[permalinks]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://skeymedia.com/permalinks-iis-isapi/</guid>
		<description><![CDATA[I&#8217;ve run WordPress here on my CentOS box for nearly 4 years and am quite familiar with the software. Recently, I had a client on a Windows system request a blog be added to their web store. Their webstore is written in ASP and runs on windows. They wanted to stay on the same domain [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve run WordPress here on my CentOS box for nearly 4 years and am quite familiar with the software.  Recently, I had a client on a Windows system request a blog be added to their web store.  Their webstore is written in ASP and runs on windows.   They wanted to stay on the same domain for SEO purposes, (thus site.com/blog/ instead of blog.site.com or a new .com).  Without the subdomain or new IP, there&#8217;s no way to change DNS for a subdirectory to a different server.  This meant I had to get it working on IIS.</p>
<p>Native installations for apache tend not to port well (or perhaps, easily) over to windows/IIS.  Thankfully, ISAPI3 from HeliconTech.com supports .htaccess files and makes the job a little easier.  WordPress works fine on windows/IIS until you want nice permalinks.</p>
<p>After MUCH searching, testing, and error log analysis, I&#8217;ve got a working solution for Windows Server 2003 with ISAPI_Rewrite 3.1.x, running php 5.2.x and mysql 5.0.x community.</p>
<ol>
<li>index.php should be set up in IIS as a default document (same place you find default.asp, index.htm, etc)</li>
<li>edit wp-settings.php<br />
Find:<br />
<pre><code>&lt;?php
</code></pre><br />
at the very top of the file.</p>
<p>Replace with:<br />
<pre><code>&lt;?php
//*****************************
//&nbsp;&nbsp;&nbsp;&nbsp;IIS FIX
//
$_SERVER[&#039;REQUEST_URI&#039;] = $_SERVER[&#039;HTTP_X_REWRITE_URL&#039;];
//*****************************
</code></pre></li>
<li>create the following htaccess file with the Helicon Manager:<br />
<pre><code>
RewriteEngine On

#RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . /blog/index.php [L]
</code></pre></p>
<ul>
<li><strong>Note:</strong>  You may need to alter the RewriteBase or the last rule to your specific location.   In my particular case, I was installed on domain.com/blog/</li>
</ul>
</li>
</ol>
<p>From here, you can edit your permalink structure as you normally would.   If the default options has index.php/ as part of the rule, you can remove that.</p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/permalinks-iis-isapi/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Rand() isn&#8217;t Random</title>
		<link>http://skeymedia.com/rand-isn-t-random/</link>
		<comments>http://skeymedia.com/rand-isn-t-random/#comments</comments>
		<pubDate>Wed, 28 Nov 2007 21:00:18 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rand Function]]></category>
		<category><![CDATA[SQL2000]]></category>

		<guid isPermaLink="false">http://skeymedia.com/rand-isn-t-random/</guid>
		<description><![CDATA[If you use Microsoft SQL 2000, you&#8217;ve probably at one point had to pull random results. The built in rand() function simply doesn&#8217;t work. It gives you a random value the first time, and every time after it is the same it seems. I found a new way to do this today after 20 pages [...]]]></description>
			<content:encoded><![CDATA[<p>If you use Microsoft SQL 2000, you&#8217;ve probably at one point had to pull random results.  The built in rand() function simply doesn&#8217;t work.  It gives you a random value the first time, and every time after it is the same it seems.</p>
<p>I found a new way to do this today after 20 pages of searching, so hopefully this will help someone else.</p>
<p><code>ORDER BY newid()</code></p>
<p>yup, it&#8217;s that simple.</p>
<p><pre><code>
SELECT
&nbsp;&nbsp;TOP 2 
&nbsp;&nbsp;&nbsp;&nbsp;field1
&nbsp;&nbsp; ,field2
FROM
&nbsp;&nbsp;TABLE
WHERE
&nbsp;&nbsp;field1 = 1
ORDER BY
&nbsp;&nbsp;newid()
</code></pre></p>
<p>To be noted, this will put a full table scan in place before it selects the top 2, so keep performance in mind.</p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/rand-isn-t-random/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intro to CURL with PHP</title>
		<link>http://skeymedia.com/intro-to-curl-with-php/</link>
		<comments>http://skeymedia.com/intro-to-curl-with-php/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 05:29:43 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[CURL]]></category>

		<guid isPermaLink="false">http://skeymedia.com/intro-to-curl-with-php/</guid>
		<description><![CDATA[CURL is a command-line style function to send data via a URL. WikiPedia has a more detailed article on what it is and does. Preface &#8211; your php installation on your server must be CURL-enabled. You can download the CURL package for free. This article assumes your server is ready to go. While CURL is [...]]]></description>
			<content:encoded><![CDATA[<p>CURL is a command-line style function to send data via a URL.  <a href="http://en.wikipedia.org/wiki/CURL">WikiPedia</a> has a more detailed article on what it is and does.</p>
<p>Preface &#8211; your php installation on your server must be CURL-enabled.  You can <a href="http://curl.haxx.se/download.html">download</a> the CURL package for free.  This article assumes your server is ready to go.</p>
<p>While CURL is not an alternative to AJAX, it can be used in similar situations where you need to send data out somewhere without the user having to go there.  In it&#8217;s most basic operation, you have some data to send out to a script.</p>
<p>We need a a simple function to handle our data, a page to process said data, and a source page where the function is called from.</p>
<p>The call page is simple.  Something as simple as:<br />
<pre><code>
&lt;?php
print sendCURL($var1, $var2, $var3)
?&gt;
</code></pre><br />
where $var1 -3 are predefined, or even hard-coded strings will suffice for basic testing.  This php block sets us up to print the output of our function:</p>
<p><pre><code>
function sendCURL($var1, $var2, $var3, $referrer=&quot;&quot;) {
&nbsp;&nbsp;$mycurl = curl_init(&quot;http://domain.com/curl_processor_page.php&quot;); 
&nbsp;&nbsp;
&nbsp;&nbsp;$fields = array(
&nbsp;&nbsp;&nbsp;&nbsp;&quot;var1&quot; =&gt; $var1,
&nbsp;&nbsp;&nbsp;&nbsp;&quot;var2&quot; =&gt; $var2,
&nbsp;&nbsp;&nbsp;&nbsp;&quot;var3&quot; =&gt; $var3
&nbsp;&nbsp;);

&nbsp;&nbsp;$curlagent = array(
&nbsp;&nbsp;&nbsp;&nbsp;&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)&quot;
&nbsp;&nbsp;);

&nbsp;&nbsp;curl_setopt($mycurl, CURLOPT_POST, 1);
&nbsp;&nbsp;curl_setopt($mycurl, CURLOPT_HEADER, 0);
&nbsp;&nbsp;curl_setopt($mycurl, CURLOPT_NOBODY, 0); 
&nbsp;&nbsp;curl_setopt($mycurl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 
&nbsp;&nbsp;curl_setopt($mycurl, CURLOPT_REFERER, $referer);
&nbsp;&nbsp;curl_setopt($mycurl, CURLOPT_RETURNTRANSFER, 1);
&nbsp;&nbsp;curl_setopt($mycurl, CURLOPT_SSL_VERIFYPEER, FALSE); 
&nbsp;&nbsp;curl_setopt($mycurl, CURLOPT_HTTPHEADER, $curlagent);
&nbsp;&nbsp;curl_setopt($mycurl, CURLOPT_POSTFIELDS, $fields); 

&nbsp;&nbsp;$response = curl_exec($mycurl); 
&nbsp;&nbsp;curl_close ($mycurl); 
&nbsp;&nbsp;
&nbsp;&nbsp;return $response;
}
</code></pre></p>
<p>This function is your basic CURL request.  Setting the variables into an array to pass, and setting headers and Options within CURL on how to process it.  The only real change you will need to make to this function are your variables in the array and your URL that you wish to send it to.</p>
<p>The curl_processor_page.php is no different than any other php page that can handle incoming $_REQUEST parameters.  Those var&#8217;s need to be set up in the function that the page is looking for, perhaps a username, password, and a realname.</p>
<p>What that script does is entirely up to you.  I won&#8217;t post an example, because I don&#8217;t want anyone to think that you can only do one method with this function set.</p>
<p>You could have the response be ANYTHING that gets returned from the processor page.  A remote login, a simple welcome screen, or even creating accounts (how do you think those auto MySpace friend adder bots work?!)</p>
<p>A useful tool when playing with CURL is the <a href="http://livehttpheaders.mozdev.org/">LiveHTTP Headers plugin for FireFox</a>.  This plugin let&#8217;s you see what&#8217;s getting sent via HTTP AS it happens.  It&#8217;s a real-time watchdog and is very useful for debugging CURL requests to see where it&#8217;s bombing.</p>
<p>Happy CURLing <img src='http://skeymedia.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/intro-to-curl-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Yahoo Releases YSlow</title>
		<link>http://skeymedia.com/yahoo-releases-yslow/</link>
		<comments>http://skeymedia.com/yahoo-releases-yslow/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 17:36:37 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/yahoo-releases-yslow/</guid>
		<description><![CDATA[YSlow is an add-on for the popular FireBug add-on for the popular browser, FireFox. Confused? It has neat tools to help you to improve your site&#8217;s load times, and rates you accordingly. I scored an F on my blog. haha Check it out: YSlow]]></description>
			<content:encoded><![CDATA[<p>YSlow is an add-on for the popular FireBug add-on for the popular browser, FireFox.  Confused?  <img src='http://skeymedia.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>It has neat tools to help you to improve your site&#8217;s load times, and rates you accordingly.   I scored an F on my blog.  haha</p>
<p>Check it out:  <a href="http://developer.yahoo.com/yslow/">YSlow</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/yahoo-releases-yslow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>BrainBench Certifications</title>
		<link>http://skeymedia.com/brainbench-certifications/</link>
		<comments>http://skeymedia.com/brainbench-certifications/#comments</comments>
		<pubDate>Sat, 21 Jul 2007 06:36:36 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/off-topic/brainbench-certifications/</guid>
		<description><![CDATA[I got an email tonight to take some free online tests. I took a couple, and scored pretty high in many areas, as I expected to, but also got stumped on a couple of the performance related issues (as I rarely deal with them). It&#8217;s fun to see how you compare to others who have [...]]]></description>
			<content:encoded><![CDATA[<p>I got an email tonight to take some free online tests.   I took a couple, and scored pretty high in many areas, as I expected to, but also got stumped on a couple of the performance related issues (as I rarely deal with them).  It&#8217;s fun to see how you compare to others who have taken the same test.</p>
<p>You can view my complete transcript here:</p>
<p><a target="_blank" href="http://www.brainbench.com/xml/bb/transcript/public/viewtranscript.xml?pid=6008022">Brain Bench Transcript</a></p>
<p><img src="http://www.skeymedia.com/wp-content/uploads/2007/07/htmlprogrammer.gif" title="Htmlprogrammer" id="image59" alt="HTML Programmer Cert" /></p>
<p><img src="http://www.skeymedia.com/wp-content/uploads/2007/07/rdbmsdeveloper.gif" title="Rdbmsdeveloper" id="image60" alt="DB Cert" /></p>
<p><img src="http://www.skeymedia.com/wp-content/uploads/2007/07/apache20administration.gif" title="Apache20administration" id="image61" alt="apache config" /></p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/brainbench-certifications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting a Global Array to work in a Function</title>
		<link>http://skeymedia.com/getting-a-global-array-to-work-in-a-function/</link>
		<comments>http://skeymedia.com/getting-a-global-array-to-work-in-a-function/#comments</comments>
		<pubDate>Mon, 09 Jul 2007 21:43:18 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/javascript/getting-a-global-array-to-work-in-a-function/</guid>
		<description><![CDATA[I recently spent a lot of time debugging this code i was working on for what I thought would be a simple onchange event. The Issue: I have sizes and colors, but not all sizes are available in all colors, so onchange of the color select box, i need to load the correct size options [...]]]></description>
			<content:encoded><![CDATA[<p>I recently spent a lot of time debugging this code i was working on for what I thought would be a simple onchange event.</p>
<p><strong>The Issue:</strong><br />
I have sizes and colors, but not all sizes are available in all colors, so onchange of the color select box, i need to load the correct size options select box.</p>
<p>Between a lot of back-end manipulation, I was able to create my front-end JS arrays of colors with the sizes that are available.  I ran into the issue that my passed in variable to the function was becoming the array, instead of calling the array.</p>
<p>For example, If I passed in &#8220;BLK&#8221; for Black, I was getting:</p>
<p><pre><code>
array[0] =&gt;B
array[1] =&gt;L
array[2] =&gt;K
array[N] =&gt; undefined
</code></pre></p>
<p>where the Nth options looped through undefined until my for loop for the options of my color box&#8217;s length had been reached.</p>
<p><strong>The Solution:</strong><br />
After scratching my head for hours and trying 232132 things, It turns out all I needed to do was to use the eval() function to evaluate my variable first, instead of treating it like a literal string.</p>
<p>Here&#8217;s the completed working source:</p>
<p><pre><code>

function popsizes(colorcode) {

var BLK= [&quot;2XL&quot;,&quot;3XL&quot;,&quot;4XL&quot;,&quot;5XL&quot;,&quot;LG&quot;,&quot;MD&quot;,&quot;SM&quot;,&quot;XL&quot;,&quot;XS&quot;];
var WH= [&quot;LG&quot;,&quot;MD&quot;];
// etc, many more color arrays

elem = document.getElementById(&quot;selcolor&quot;);
sizelist = eval(colorcode);

for (i=0; i&lt;elem .options.length; i++) {
&nbsp;&nbsp;document.getElementById(&quot;selsize&quot;).options[i] = new Option(sizelist[i]);
}
}

</code></pre></p>
<p>That script is powered by the onchange event from the form:</p>
<p><pre><code>
&lt;tr&gt;
&nbsp;&nbsp;&lt;td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;select &quot;id=&quot;selcolor&quot; name=&quot;color&quot; onchange=&quot;popsizes(this.options[this.selectedIndex].value);&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option value=&quot;WH&quot;&gt;White&lt;/option&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option value=&quot;BLK&quot;&gt;Black&lt;/option&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option value=&quot;&quot;&gt; Many more colors, etc .... &lt;/option&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/select&gt;
&nbsp;&nbsp;&lt;/td&gt;
&nbsp;&nbsp;&lt;td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;select &quot;id=&quot;selsize&quot; name=&quot;size&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option value=&quot;&quot;&gt;Select Color First&lt;/option&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/select&gt;
&nbsp;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
</code></pre></elem></code></p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/getting-a-global-array-to-work-in-a-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Around Poor Table Design</title>
		<link>http://skeymedia.com/scripting-around-poor-table-design/</link>
		<comments>http://skeymedia.com/scripting-around-poor-table-design/#comments</comments>
		<pubDate>Tue, 16 Jan 2007 18:54:52 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/classicasp/scripting-around-poor-table-design/</guid>
		<description><![CDATA[We&#8217;ve all seen it. Some 3rd party database you&#8217;ve inherited from someone else was simply never designed with scalability and portability in mind. There&#8217;s no hope to change it, as it will break the original design and thus the original application that it is supporting. In a recent case for me, I had the problem [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve all seen it.  Some 3rd party database you&#8217;ve inherited from someone else was simply never designed with scalability and portability in mind.  There&#8217;s no hope to change it, as it will break the original design and thus the original application that it is supporting.<br />
<span id="more-49"></span><br />
In a recent case for me, I had the problem of dealing with a &#8216;Quantity Discount&#8217; table.  ie, Buy one and its normal price, buy 2 or more and it&#8217;s a dollar less per item.  The table I had to work with was a disaster.  There were no data pairs for pricing and quantity.  Instead, it was one row per item number with 9 qty fields and 9 corresponding pricing fields similar to this:</p>
<p><pre><code>
itemno, offno, qty1, qty2, ... qty9, pri1, pri2, ... pri9
</code></pre></p>
<ul>
<li>qty1 matched with pri1, qty2 matched with pri2 and so forth through the 9 iterations. </li>
<li>itemno is the item number/sku in the database inventory table</li>
<li>offno is relating to the offer code, or promo code.  Depending on the promo, certain products are priced differently.</li>
<li>the max discount field in the qty ranges was denoted by 999999 in the last field.  </li>
<li>any non-used qty ranges after the max were filled in with 0&#8242;s.</li>
<li>Prices are stored in whole numbers (x100) so as to eliminate decimal points.  ($19.99 was stored as 1999)</li>
</ul>
<p>The current setup simply printed out every price, line item by line item, until the 999999 item was reached, and then &#8216;or more&#8217; was added on to the end of it.</p>
<p>What the client wanted to display, was <b>Only</b> the upsale prices.  Ie, if 1 and 2 items were regular price, but 3 or more were at a discount, all they wanted to show was the main price as usual, along with &#8220;Buy 3 or more, $XX.XX&#8221;.  this posed even a more difficult problem when there were ranges in the prices, ie, Buy 1-2 at normal price (no display &#8211; same as regular price), Buy 3-4, $XX.XX, Buy 5 or more, $XX.XX</p>
<p>One stored procedure, one temp db table, and one two-dimensional indexed array later, I came up with the solution (with the help of a couple fine members on a dev mailing list I might add)</p>
<p>So, I waved goodbye to Function multiprice, and created Function multiprice_new  <img src='http://skeymedia.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here&#8217;s the code I used to pull this off using Classic ASP as the scripting language, and MS SQL2000 as the DBMS.</p>
<p>This function takes on the item number (itemno), as well as the generic price of the single item cost (sPrice) from the main script.</p>
<p><pre><code>
Function multiprice_new(itemno, sPrice)

&nbsp;&nbsp;Dim myqty()
&nbsp;&nbsp;Dim myprice()

&nbsp;&nbsp;Set cn = Server.CreateObject(&quot;ADODB.Connection&quot;)
&nbsp;&nbsp;Set cmd = Server.CreateObject(&quot;ADODB.Command&quot;)
&nbsp;&nbsp;
&nbsp;&nbsp;cn.Open DB
&nbsp;&nbsp;Set cmd.ActiveConnection = cn
&nbsp;&nbsp;cmd.CommandText = &quot;multiprice_new&quot;
&nbsp;&nbsp;cmd.CommandType = adCmdStoredproc
&nbsp;&nbsp;Set objRs = Server.CreateObject(&quot;ADODB.Recordset&quot;)

&nbsp;&nbsp;xitemno2 = trim(itemno)
&nbsp;&nbsp;xitemno2 = Replace(Space(8-len(xitemno2)),&quot; &quot;,&quot;0&quot;) &amp; xitemno2&nbsp;&nbsp;&nbsp;&nbsp; &#039; this fixes some formatting issues on the itemno
&nbsp;&nbsp;src = trim(session(&quot;src&quot;))&nbsp;&nbsp;&nbsp;&nbsp;&#039; this passes in the source code for the correct promo pricing

&nbsp;&nbsp;With cmd
&nbsp;&nbsp;&nbsp;&nbsp;.Parameters.Append cmd.CreateParameter(&quot;@itemno&quot;, adVarChar, adParamInput, 25, xitemno2)
&nbsp;&nbsp;&nbsp;&nbsp;.Parameters.Append cmd.CreateParameter(&quot;@src&quot;, adVarChar, adParamInput, 25, src)
&nbsp;&nbsp;&nbsp;&nbsp;.Parameters.Append cmd.CreateParameter(&quot;@qty&quot;, adInteger, adParamOutput, , 0)
&nbsp;&nbsp;&nbsp;&nbsp;.Parameters.Append cmd.CreateParameter(&quot;@price&quot;, adInteger, adParamOutput, , 0)
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;End with

&nbsp;&nbsp;
&nbsp;&nbsp;Set objRS = cmd.Execute
&nbsp;&nbsp;x= 0
&nbsp;&nbsp;Do While Not objRs.EOF

&nbsp;&nbsp;&nbsp;&nbsp;ReDim Preserve&nbsp;&nbsp;myqty(x)
&nbsp;&nbsp;&nbsp;&nbsp;ReDIm Preserve&nbsp;&nbsp;myprice(x)

&nbsp;&nbsp;&nbsp;&nbsp;myqty(x) = objRs(0)
&nbsp;&nbsp;&nbsp;&nbsp;myprice(x) = objRs(1)/100&nbsp;&nbsp;&nbsp;&nbsp;&#039; remember, the prices were stored with no cents, so this generates the cents portion of the price

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objRs.MoveNext
&nbsp;&nbsp;&nbsp;&nbsp;x = x+1
&nbsp;&nbsp;&nbsp;&nbsp;Loop

&nbsp;&nbsp;
&nbsp;&nbsp;Dim qtyranges(2,9), price, rangecount
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;price = 0
&nbsp;&nbsp;rangecount = 0

&nbsp;&nbsp;limiter = UBound(myprice)

&nbsp;&nbsp;for j = 0 to limiter
&nbsp;&nbsp;&nbsp;&nbsp;price = myprice(j)
&nbsp;&nbsp;&nbsp;&nbsp;i = j + 1
&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;If i&lt;limiter then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Do While price = myprice(i)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i = i+1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loop
&nbsp;&nbsp;&nbsp;&nbsp;End if

&nbsp;&nbsp;&nbsp;&nbsp;qtyranges(0,rangecount) = j
&nbsp;&nbsp;&nbsp;&nbsp;qtyranges(1,rangecount) = i
&nbsp;&nbsp;&nbsp;&nbsp;qtyranges(2,rangecount) = price

&nbsp;&nbsp;&nbsp;&nbsp;rangecount = rangecount+1
&nbsp;&nbsp;&nbsp;&nbsp;j = i
&nbsp;&nbsp;Next

&nbsp;&nbsp;
&nbsp;&nbsp;for j = 0 to rangecount-1
&nbsp;&nbsp;&nbsp;&nbsp;If qtyranges(0,j) = 0 Then 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qtyranges(0,j) = 1
&nbsp;&nbsp;&nbsp;&nbsp;End If
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;If sPrice &lt; (CDbl(qtyranges(2,j)) + CDbl(.01)) Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039; skip...&nbsp;&nbsp;this is not a cheaper price than normal.&nbsp;&nbsp;They only want to show the discounted qty ranges.
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot;Buy &quot; &amp; qtyranges(0,j)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If qtyranges(1,j) &lt;&gt; &quot;&quot; Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If qtyranges(1,j) = limiter+1 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot; or more&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If qtyranges(0,j) = qtyranges(1,j) then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039; DO nothing (avoids Buy 1-1,)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot;-&quot; &amp; qtyranges(1,j)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End if
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End if
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot;, Pay $&quot;&amp; qtyranges(2,j) &amp; &quot; each&lt;br /&gt;&quot;
&nbsp;&nbsp;&nbsp;&nbsp;End if
&nbsp;&nbsp;next

&nbsp;&nbsp;response.write &quot;&lt;br /&gt;&lt;br /&gt;&quot;

&nbsp;&nbsp;&nbsp;&nbsp;objRS.Close&nbsp;&nbsp;
&nbsp;&nbsp;cn.Close()
&nbsp;&nbsp;Set cn = Nothing

&nbsp;&nbsp;multiprice_new=Success

End function
&lt;/limiter&gt;</code></pre></p>
<p>This function called the following stored procedure:</p>
<p><pre><code>
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

ALTER&nbsp;&nbsp;procedure multiprice_new
(
@itemno varchar(25),
@src varchar(25),
@qty int output,
@price int output
)

as

set nocount on

begin

declare @t table
(
itemno varchar(25),
qty int,
price int
)

insert into @t

select itemno, cast(qty1 as int), pri1
from multiprice
where itemno = &#039;&#039; + @itemno + &#039;&#039;
and offno = &#039;&#039; + @src + &#039;&#039;
UNION ------------
select itemno, cast(qty2 as int), pri2
from multiprice
where itemno = &#039;&#039; + @itemno + &#039;&#039;
and offno = &#039;&#039; + @src + &#039;&#039;
UNION ------------
select itemno, cast(qty3 as int), pri3
from multiprice
where itemno = &#039;&#039; + @itemno + &#039;&#039;
and offno = &#039;&#039; + @src + &#039;&#039;
UNION ------------
select itemno, cast(qty4 as int), pri4
from multiprice
where itemno = &#039;&#039; + @itemno + &#039;&#039;
and offno = &#039;&#039; + @src + &#039;&#039;
UNION ------------
select itemno, cast(qty5 as int), pri5
from multiprice
where itemno = &#039;&#039; + @itemno + &#039;&#039;
and offno = &#039;&#039; + @src + &#039;&#039;
UNION ------------
select itemno, cast(qty6 as int), pri6
from multiprice
where itemno = &#039;&#039; + @itemno + &#039;&#039;
and offno = &#039;&#039; + @src + &#039;&#039;
UNION ------------
select itemno, cast(qty7 as int), pri7
from multiprice
where itemno = &#039;&#039; + @itemno + &#039;&#039;
and offno = &#039;&#039; + @src + &#039;&#039;
UNION ------------
select itemno, cast(qty8 as int), pri8
from multiprice
where itemno = &#039;&#039; + @itemno + &#039;&#039;
and offno = &#039;&#039; + @src + &#039;&#039;
UNION ------------
select itemno, cast(qty9 as int), pri9
from multiprice
where itemno = &#039;&#039; + @itemno + &#039;&#039;
and offno = &#039;&#039; + @src + &#039;&#039;

delete from @t
where price = 0

select qty, price
from @t
order by qty asc

set nocount off 

end

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

</code></pre></p>
<p>Finally, to call it from our main product display page, we simply call the function:</p>
<p><pre><code>
itemno = request(&quot;itemno&quot;)
sPrice = **some other function here that gets pricing from inventory table (along with the product details, etc) **
Ssuccess=multiprice_new(itemno, sPrice)
</code></pre></p>
<p>And that will print out something like:</p>
<p><pre><code>
Your Price: $14.98
Buy 4 or more, Pay $10.98 each
</code></pre><br />
assuming qty1, qty2, qty3 were priced at 14.98, and qty 4 was priced at 10.98, and qty5 field had the 999999 indicator for &#8216;or more&#8217; in it.  Confusing, yes.  Poor table design at it&#8217;s finest <img src='http://skeymedia.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<hr />
<p>So, what did we do here?</p>
<p>We had a problem table that would normally be pretty useless to us.<br />
We made our own temp table that would be worthwhile to us, filling it in line by line from the bad table via unions for each of the qty/price pairs based on item number.  The real problem here, is that is is impossible to group by from the original table to get the desired result.  Thus, we made our own table and via the select inserts, can put the data how it can be usable to us.</p>
<p>Once we had a workable table, we created a loop to set up our ranges of quantities.  1,2,3;  or 1-4,5-10, 11 or more.  No matter what the data, our loop will create our starting integer (i) along with its matching trailing integer (j) and that ranges corresponding price (price).</p>
<p>Finally, we check to see if the price is less than the standard price to make sure its actually a better deal, and thus, an upsell based on quantity.  If not, skip.  If it is, print out the range and its price.  Loop through until all fields are exhausted and the 999999 item has been reached, thus &#8216;or more&#8217;.<br />
We also do a check to make sure that the item range is not the same as itself (&#8220;Buy 1-1, $XX.XX&#8221;) as that just looks stupid and is not a range, afterall.  I put a little comment in the loop above about this.</p>
<p>With some clever looping, and a lot of coding, the desired result has been achieved.</p>
<p>Next time you&#8217;re handed a database table that seems impossible to get the data you need from it, don&#8217;t fret.  There&#8217;s always a way to get what you need so long as you have access to the data at all.  A little converting, kicking and punching, and you will be able to print out just about anything in any format a client desires.  Even if that client is your Uncle Charlie.</p>
<p>Comments, thoughts, and suggestions appreciated as always.</p>
<p><i>Big thanks to Matt Warden for coming up with the qtyranges() array concept which, with some tweaking, was the key to making this successful.</i></p>
<p>-Brian</p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/scripting-around-poor-table-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick SQL Date Functions and Queries</title>
		<link>http://skeymedia.com/quick-sql-date-functions-and-queries/</link>
		<comments>http://skeymedia.com/quick-sql-date-functions-and-queries/#comments</comments>
		<pubDate>Fri, 12 Jan 2007 10:50:05 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/sql/quick-sql-date-functions-and-queries/</guid>
		<description><![CDATA[It&#8217;s easy to grab the date from a field in a database so long as you saved a timestamp field along with your data row. However, there are often times in developing stored procedures and advanced queries where one needs to look up events in the future, or past based on some other reference point [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s easy to grab the date from a field in a database so long as you saved a timestamp field along with your data row.  However, there are often times in developing stored procedures and advanced queries where one needs to look up events in the future, or past based on some other reference point from either the data at hand, or an arbitrary date, such as in a calendar.<br />
<span id="more-48"></span><br />
A perfect example of this is setting up some sort of date book for say a Widgets Club, which meets every Monday.   The Secretary then posts his/her meetings notes to the club&#8217;s website.  You, being the savvy developer, don&#8217;t want to go in every Tuesday and put the new post up&#8211;  you want it dynamic and to do it itself.</p>
<p>So, the question is:  How do we get the date of last Monday to display the latest notes on our Widgets Club website?  With the built in functions of SQL, we can easily derive the date of last Monday:<br />
<pre><code>
SELECT 
&nbsp;&nbsp;convert(varchar,dateadd(dd,0,DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)),101) 
&nbsp;&nbsp;as &#039;Monday&#039;
</code></pre></p>
<p>While it looks like a huge mess, it is pretty straight forward.  </p>
<p>Posted today, Friday 01/12/07, this query returns 01/08/2007 as Monday of this week.</p>
<p>Used inline with another query, or as part of the where clause, this code could be used to display the notes, probably something similar to this:</p>
<p><pre><code>
SELECT
&nbsp;&nbsp;meetingdate, mettingnotes
FROM
&nbsp;&nbsp;MeetingNotesTable
WHERE
&nbsp;&nbsp;meetingdate BETWEEN convert(varchar,dateadd(dd,0,DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)),101) + &#039; 00:00:00&#039; AND getdate()
</code></pre></p>
<p>This will get us anything that was posted between today and this week&#8217;s Monday.</p>
<p>Perhaps for this example a more practical solution would be to just sort by an auto_ID field descending, limiting to 1 result, but there are valid practical uses for this query.</p>
<p>It can also be altered to say get the previous weeks&#8217; Monday date.  Simply add in the -7 to the query like so:</p>
<p><pre><code>
SELECT 
&nbsp;&nbsp;convert(varchar,dateadd(dd,-7,DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)),101) 
&nbsp;&nbsp;as &#039;Last Monday&#039;
</code></pre></p>
<p>Or, perhaps you have a product that only ships out on Monday&#8217;s.  You want to tell the customer what Date their item will ship on.  You could use a similar version of this query:</p>
<p><pre><code>
SELECT
&nbsp;&nbsp;convert(varchar,dateadd(dd,7,DATEADD(wk, DATEDIFF(wk,0,getdate()),0)),101) 
&nbsp;&nbsp;as &#039;Next Monday&#039;
</code></pre></p>
<p>Delayed items?  Shipping on next Tuesday instead?  No problem.  Just add 1 day to the DATEDIFF portion:</p>
<p><pre><code>
SELECT
&nbsp;&nbsp;convert(varchar,dateadd(dd,7,DATEADD(wk, DATEDIFF(wk,0,getdate()),1)),101) 
&nbsp;&nbsp;as &#039;Next Tuesday&#039;
</code></pre></p>
<p>In all of these queries, you could sub out the getdate() function for a timestamp field from your database instead should it fit your application better, for example, the order date.</p>
<p>There are countless possibilities for generating past and future dated queries based off of a known date.  Be it a data field, or the current date the script is run.  Knowing how to use them is the first step.  Once you are able to grasp how the dateadd, datepart, and other date functions work, you can truely see the built in power of the RDBMS system.</p>
<p><i>(Note:  These were designed with MS SQL Server 2000.  Your DBMS may handle some of these functions differently)</i></p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/quick-sql-date-functions-and-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RFC-32 Date Formatting with Classic ASP</title>
		<link>http://skeymedia.com/rfc-32-date-formatting-with-classic-asp/</link>
		<comments>http://skeymedia.com/rfc-32-date-formatting-with-classic-asp/#comments</comments>
		<pubDate>Fri, 22 Dec 2006 07:37:19 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/classicasp/rfc-32-date-formatting-with-classic-asp/</guid>
		<description><![CDATA[Tonight I was working on an RSS package for a client of mine. Having dealt with RSS feeds in the past, I figured it wouldn&#8217;t be a big deal. However, my experience with them has always been on the &#8216;receiving&#8217; end of it, imploding out the &#60;item&#62;&#60;/item&#62;&#8217;s and making sense of the xml. For the [...]]]></description>
			<content:encoded><![CDATA[<p>Tonight I was working on an RSS package for a client of mine.  Having dealt with RSS feeds in the past, I figured it wouldn&#8217;t be a big deal.  However, my experience with them has always been on the &#8216;receiving&#8217; end of it, imploding out the <code>&lt;item&gt;&lt;/item&gt;</code>&#8217;s and making sense of the xml.</p>
<p>For the most part, setting up the RSS2.0 feed was pretty straight forward.  The one thing that took a little time to manipulate was the RFC-32 date/time formatting that RSS Feeds require in order to validate.   And we all know how important validation is <img src='http://skeymedia.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<span id="more-47"></span><br />
So, I came up with a simple little function to help you out and save you some time in your own Classic ASP RSS feeds.</p>
<p><pre><code>
&lt; %
Function getrfcdate(mydate)
&nbsp;&nbsp;&#039;format date in rfc-32
&nbsp;&nbsp;&#039;format:&nbsp;&nbsp;Wed, 02 Oct 2002 08:00:00 EST

&nbsp;&nbsp;If Hour(mydate)&lt; 10 Then
&nbsp;&nbsp;&nbsp;&nbsp;myhour = &quot;0&quot; &amp; Hour(mydate)
&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;myhour = Hour(mydate)
&nbsp;&nbsp;End If

&nbsp;&nbsp;If minute(mydate)&lt; 10 Then
&nbsp;&nbsp;&nbsp;&nbsp;myminute = &quot;0&quot; &amp; minute(mydate)
&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;myminute = minute(mydate)
&nbsp;&nbsp;End If

&nbsp;&nbsp;If second(mydate)&lt; 10 Then
&nbsp;&nbsp;&nbsp;&nbsp;mysecond = &quot;0&quot; &amp; second(mydate)
&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;mysecond = second(mydate)
&nbsp;&nbsp;End If

&nbsp;&nbsp;If day(mydate)&lt; 10 Then
&nbsp;&nbsp;&nbsp;&nbsp;myday = &quot;0&quot; &amp; day(mydate)
&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;myday = day(mydate)
&nbsp;&nbsp;End If

&nbsp;&nbsp;mymonth = monthName(Month(mydate),true)

&nbsp;&nbsp;myyear = Year(mydate)

&nbsp;&nbsp;dayname = WeekdayName(Weekday(mydate),true)

&nbsp;&nbsp;mydate = dayname &amp; &quot;, &quot; &amp; myday &amp; &quot; &quot; &amp; mymonth &amp; &quot; &quot; &amp; myyear &amp; &quot; &quot; &amp; myhour &amp; &quot;:&quot; &amp; myminute &amp; &quot;:&quot; &amp; mysecond &amp; &quot; EST&quot;

&nbsp;&nbsp;getrfcdate = mydate
End Function

%&gt;
</code></pre></p>
<p>To call it, simply pass in a normal date/time string, such as now() or a getdate() recordset variable return from a sql query:</p>
<p><pre><code>
&lt; %
response.write &quot;&lt;pubDate&gt;&quot;&amp; getrfcdate(now()) &amp;&quot;&lt;/pubDate&gt;&quot; &amp; vbcrlf
%&gt;
</code></pre></p>
<p>There you go <img src='http://skeymedia.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/rfc-32-date-formatting-with-classic-asp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lightbox and WordPress- The Easy Way</title>
		<link>http://skeymedia.com/lightbox-and-wordpress-the-easy-way/</link>
		<comments>http://skeymedia.com/lightbox-and-wordpress-the-easy-way/#comments</comments>
		<pubDate>Sun, 30 Jul 2006 12:39:32 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/off-topic/lightbox-and-wordpress-the-easy-way/index.html</guid>
		<description><![CDATA[I recently wrote an article on BloggerSkills.com on how to better utilize the Lightbox functions within a WordPress blog. No more manually typing rel=&#8221;lightbox&#8221; attributes! read more&#160;&#124;&#160;digg story]]></description>
			<content:encoded><![CDATA[<p>I recently wrote an article on BloggerSkills.com on how to better utilize the Lightbox functions within a WordPress blog.  No more manually typing rel=&#8221;lightbox&#8221; attributes!</p>
<p><a href="http://www.bloggerskills.com/lightbox-and-wordpress-the-easy-way/">read more</a>&nbsp;|&nbsp;<a href="http://digg.com/programming/Lightbox_and_WordPress_The_Easy_Way">digg story</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/lightbox-and-wordpress-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Loopy &#8211; Nested Javascript Loops</title>
		<link>http://skeymedia.com/getting-loopy-nested-javascript-loops/</link>
		<comments>http://skeymedia.com/getting-loopy-nested-javascript-loops/#comments</comments>
		<pubDate>Fri, 26 May 2006 18:13:35 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[loops]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/javascript/getting-loopy-nested-javascript-loops/index.html</guid>
		<description><![CDATA[Complex loops with Javascript can get tricky. Double-nested loops, dynamic field names, and all kinds of other things can leave a programmers head spinning. Let&#8217;s get Loopy and tackle this in a nice programatical manner. Recently presented with a form similar to a questionaire, there were a bunch of questions, each with the possibility of [...]]]></description>
			<content:encoded><![CDATA[<p>Complex loops with Javascript can get tricky.  Double-nested loops, dynamic field names, and all kinds of other things can leave a programmers head spinning.  Let&#8217;s get Loopy and tackle this in a nice programatical manner.</p>
<p>Recently presented with a form similar to a questionaire, there were a bunch of questions, each with the possibility of multiple answer options and a comment box.  To make matters worse, I needed to check if there were comments entered when a certain option was selected.  Rather than go through one by one and create a huge function, I tapped into the power of loops, and the power of dynamic form element naming.</p>
<p>Let&#8217;s say our form is a questionaire with radio buttons for options and a comment box.  The form would look something like this:</p>
<p><pre><code>
&lt;div&gt;
&nbsp;&nbsp;&lt;form id=&quot;frmdefault&quot; onsubmit=&quot;validateForm();&quot; method=&quot;post&quot; action=&quot;results.php&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;table&gt;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;Q1&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;strong&gt;How good are you at javascript?&lt;/strong&gt;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;input type=&quot;radio&quot; id=&quot;q1&quot; name=&quot;q1&quot; value=&quot;Great&quot; /&gt;Great!&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;input type=&quot;radio&quot; id=&quot;q1&quot; name=&quot;q1&quot; value=&quot;Average&quot; /&gt;Average&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;input type=&quot;radio&quot; id=&quot;q1&quot; name=&quot;q1&quot; value=&quot;Bad&quot; /&gt;Bad&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;input type=&quot;radio&quot; id=&quot;q1&quot; name=&quot;q1&quot; value=&quot;NA&quot; /&gt;N/A&lt;/td&gt;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;textarea id=&quot;q1_comments&quot; name=&quot;q1_comments&quot; rows=&quot;2&quot; cols=&quot;5&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;Q2&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;strong&gt;How do you think this tutorial rates?&lt;/strong&gt;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;input type=&quot;radio&quot; id=&quot;q2&quot; name=&quot;q2&quot; value=&quot;Great&quot; /&gt;Great!&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;input type=&quot;radio&quot; id=&quot;q2&quot; name=&quot;q2&quot; value=&quot;Average&quot; /&gt;Average&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;input type=&quot;radio&quot; id=&quot;q2&quot; name=&quot;q2&quot; value=&quot;Bad&quot; /&gt;Bad&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;input type=&quot;radio&quot; id=&quot;q2&quot; name=&quot;q2&quot; value=&quot;NA&quot; /&gt;N/A&lt;/td&gt;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;textarea id=&quot;q2_comments&quot; name=&quot;q2_comments&quot; rows=&quot;2&quot; cols=&quot;5&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td colspan=&quot;7&quot;&gt;&lt;input type=&quot;submit&quot; value=&quot;Validate Form&quot; /&gt;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/table&gt;
&nbsp;&nbsp;&lt;/form&gt;
&lt;/div&gt;
</code></pre></p>
<p>This makes our nice little form.  Of course, you can make it into nice table-less layout and all that, but that is beyond the scope of this article, so I used a table.</p>
<p>Let&#8217;s say that we want to:</p>
<ol>
<li>Make sure a radio option is selected for each question</li>
<li>require a comment to be entered in the textarea if &#8220;Bad&#8221; is selected</li>
</ol>
<p>In order to do this, we need to first loop through our radio buttons to see if one is selected.  If &#8220;bad&#8221; is selected, prompt for comments to be entered.  Finally, we need to loop and repeat the above for every question.</p>
<p>In less than 30 lines of (well-formatted) code, we can set up a double-looping function that does all of this, will work for an infinite amount of questions or possible answers (except a single answer-  but, you shouldn&#8217;t be using radio buttons for a single element choice anyway).  I will explain the code below the function:</p>
<p><pre><code>
&lt;script type=&quot;text/javascript&quot;&gt;

function validateForm() {
&nbsp;&nbsp;var theform = document.getElementById(&quot;frmdefault&quot;);

&nbsp;&nbsp;for (i=1; i&amp;lt;3; i++)
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;for (j=0; j&lt;theform .elements[&quot;q&quot;+i].length; j++)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (theform.elements[&quot;q&quot;+i][j].checked)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (theform.elements[&quot;q&quot;+i][j].value == &quot;Bad&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(theform.elements[&quot;q&quot;+i+&quot;_comments&quot;].value == &quot;&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Comments required for Q&quot;+i+&quot; when Bad is selected&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;theform.elements[&quot;q&quot;+i+&quot;_comments&quot;].focus();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Please select an option&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
}
&lt;/script&gt;
&lt;/theform&gt;&lt;/script&gt;</code></pre></p>
<p>It looks very complex and tricky, but as we go through it you will see it makes a lot of sense.  The outer loop is set for the number of questions we have.  In this case, we have 2.  You could port this a step further an make this number count dynamic as well.  (In most cases though, I feel as if that&#8217;s an un-necessary step as most polls or scripts like this won&#8217;t change once made.  If you are running some kind of dynamic form generator, then yes, another step will need to be added to find how many questions there are. Basically, you&#8217;d have to add another loop around all of the above that counts how many questions there are.)</p>
<p>Notice, we start with i=1 instead of the common i=0.  This is because our questionaire starts with question 1, not question 0.  It makes things easier to address in the inner functions.  Because of this, we also must up our incremented variable to i&lt;3 instead of i&lt;2, because of the increased initialized variable.  Another option would be to use i< =2, thus allowing for it to be equal to the max index.</p>
<p>The outer loop, <em>i</em>, will call the inner loop <em>j</em>, <em>i</em> times.  Inside the inner loop, we need to dynamically address how many radio buttons there are.  The length function figures this out for us and begins our data check to ensure at least one element is checked per our requirements.  Note that we are using ["q"+i].  This evaluates to our question number based off the outer loop.  If the element array does not have one checked, it will return false and prompt the user to select one.  If there is an element checked, it will then look and see if that checked value = &#8220;Bad&#8221;.  If it is, it then checks to see if there is anything in the textarea field for comments.  If not, we return home free and we return to the outer loop for testing the question count to see if we need to do this all over again for the next question, if one exists.  When all is passed, the form will submit to the target in the action attribute of the form tag, in our example, results.php.  </p>
<p>Of course, this all depends on Javascript being enabled, and in a browser than supports the getElementById() functionality.  Thus, it is important to also use server-side scripting to double check the submitted results.  The Javascript just adds a friendly alert so that the whole page doesn&#8217;t need to be submitted every time an error occurs.</p>
<p>Have a better idea?  I&#8217;m sure this code can be improved upon, and thus I&#8217;m curious to hear if anyone else has a similar function set up for this type of form checking.  I appreciate your comments, as always.</p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/getting-loopy-nested-javascript-loops/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Problematic SQL Sorting</title>
		<link>http://skeymedia.com/problematic-sql-sorting/</link>
		<comments>http://skeymedia.com/problematic-sql-sorting/#comments</comments>
		<pubDate>Thu, 25 May 2006 16:17:44 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/sql/problematic-sql-sorting/index.html</guid>
		<description><![CDATA[Sometimes, all you want to do is a simple ORDER BY, but it just doesn&#8217;t work. SQL has some quirks when trying to sort &#8220;text&#8221; numbers, especially when they are decimal numbers. Consider the following Database table, myTable: Code&#160;&#160;varchar(5)&#160;&#160;&#124; Descr varchar(100) ------------------&#124;-------------------- 1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124; Code 1 1.1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124; Code 1 point 1 1.2&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#124; Code [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, all you want to do is a simple ORDER BY, but it just doesn&#8217;t work.  SQL has some quirks when trying to sort &#8220;text&#8221; numbers, especially when they are decimal numbers.</p>
<p>Consider the following Database table, myTable:</p>
<p><pre><code>
Code&nbsp;&nbsp;varchar(5)&nbsp;&nbsp;| Descr varchar(100)
------------------|--------------------
1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 1
1.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 1 point 1
1.2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 1 point 2
2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 2
3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 3
10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Code 10
11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Code 11
20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Code 20
</code></pre></p>
<p>If you wanted to do a simply query to order by the Code field, one would think that a simple ORDER BY would do the trick.  </p>
<p><pre><code>
SELECT 
&nbsp;&nbsp; Code
&nbsp;&nbsp;,Descr
FROM
&nbsp;&nbsp; myTable
ORDER BY
&nbsp;&nbsp; Code ASC
</code></pre></p>
<p>Unfortunately, it doesn&#8217;t. This produces:</p>
<p><pre><code>
Code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Descr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
------------------|--------------------
1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 1
1.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 1 point 1
1.2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 1 point 2
10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Code 10
11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Code 11
2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 2
20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Code 20
3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 3
</code></pre></p>
<p>In order for the DBMS to interpret the Code field as a Number, not as text, we need to CAST it to a numeric datatype, in this case i will use float.</p>
<p><pre><code>
SELECT 
&nbsp;&nbsp; cast(Code as float) AS &#039;Code&#039;
&nbsp;&nbsp;,Descr
FROM
&nbsp;&nbsp; myTable
ORDER BY
&nbsp;&nbsp; Code ASC
</code></pre></p>
<p>Yup, this doesn&#8217;t work either.  Suddenly you may find yourself with 1.999999999999 instead of your code 2.  The rounding mechanism is not perfect.  So, we need to take this a step further, and once again re-cast our float as a varchar.  This will fix the rounding problem.</p>
<p><pre><code>
SELECT 
&nbsp;&nbsp; cast(cast(Code as float)as varchar) AS &#039;Code&#039;
&nbsp;&nbsp;,Descr
FROM
&nbsp;&nbsp; myTable
ORDER BY
&nbsp;&nbsp; Code ASC
</code></pre></p>
<p>The above will produce your results table nice and neat and perfectly sorted.</p>
<p><pre><code>
Code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Descr
------------------|--------------------
1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 1
1.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 1 point 1
1.2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 1 point 2
2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 2
3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Code 3
10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Code 10
11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Code 11
20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Code 20
</code></pre></p>
<p>Knowing how to work around the tweaks of any system will save you a lot of time and hair pulling.  Fortunately, there are built in functions that make it easy on us developers, but sometimes finding them can be a little tricky.   </p>
<p>This is the first of my SQL articles to come, so check back often for new articles and updates.</p>
<p><em>This code was tested for MSSQL Server 2000.  Rounding quirks  may react differently in your DBMS.</em></p>
<p>Like this article?  Please <a href="http://www.digg.com/programming/Problematic_SQL_Sorting">Digg it</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/problematic-sql-sorting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Is it Time to Abandon 800&#215;600?</title>
		<link>http://skeymedia.com/is-it-time-to-abandon-800x600/</link>
		<comments>http://skeymedia.com/is-it-time-to-abandon-800x600/#comments</comments>
		<pubDate>Tue, 16 May 2006 19:32:53 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/xhtml-and-css/is-it-time-to-abandon-800x600/index.html</guid>
		<description><![CDATA[Yesterday, May 15th 2006, Yahoo! Inc. released a link in their blog to a preview page of their new layout which perhaps may set the standard in pushing away from developing for 800&#215;600 resolution. It will not fit without horizontal scrollbars at 800&#215;600 resolution, but fits the screen nice and neatly with just a small [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, May 15th 2006, Yahoo! Inc. released a link in their <a href="http://www.ysearchblog.com/archives/000304.html">blog</a> to a <a href="http://www.yahoo.com/?p=1147806953">preview page of their new layout</a> which perhaps may set the standard in pushing away from developing for 800&#215;600 resolution.  It will not fit without horizontal scrollbars at 800&#215;600 resolution, but fits the screen nice and neatly with just a small padding around the edges in 1024&#215;768.  Frankly, I&#8217;m suprised to see them make the move to a fixed-width, non-fluid template.</p>
<p>The new left navigation menu is also very cutting edge &#8220;web 2.0&#8243;.  While still sorted in alphabetical order, it utilizes web 2.0-style &#8220;tags&#8221; in which the more popular items are in a larger font.</p>
<p>Will this release finally give the last push to totally abandon 800&#215;600?  I don&#8217;t know if i&#8217;m quite ready for that yet.  I for one know that both my parents in their early 50&#8242;s use 800&#215;600 on their 17&#8243; CRT, and they have a hard time seeing that sometimes, so I cannot imagine them moving to 1024&#215;768.  Perhaps, this will become the leading accesibility issue, perhaps it will have no effect.  But I for one still believe in making sites fluid, or at the very least, not so wide as too force a horizontal scroll bar.</p>
<hr />
<p><i>EDIT: 5/17/2006, 14:36 GMT -5</i></p>
<p>I think it is fitting that after nearly 20,000 views and 1500+ Digg&#8217;s to this page, that i include the real-time image of the resolution stats visiting this page.  While only 2% as of this writing are on 800&#215;600, the results are skewed as us techies are more apt to have better equipment.</p>
<p><img src="http://s24.sitemeter.com/rpc/v6/server.asp?a=GetChart&#038;n=9&#038;p1=s24skeymedia&#038;p2=&#038;p3=73&#038;p4=0&#038;p5=63%2E239%2E47%2E21&#038;p6=HTML&#038;p7=1&#038;p8=%2E%3Fa%3Dstatistics&#038;p9=&#038;rnd=8317" title="Server" alt="Pie Chart for Resolutions" /></p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/is-it-time-to-abandon-800x600/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Microsoft.com Goes Valid</title>
		<link>http://skeymedia.com/microsoftcom-goes-valid/</link>
		<comments>http://skeymedia.com/microsoftcom-goes-valid/#comments</comments>
		<pubDate>Fri, 05 May 2006 17:24:29 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/xhtml-and-css/microsoftcom-goes-valid/index.html</guid>
		<description><![CDATA[Hell must have frozen over sometime in the past month or so. With the newest rendition of the Microsoft.com Home Page, the markup actually passes W3 validation for HTML 4.01 transitional. Further noteworthy, is that there are accessibility features in place, such as &#8220;Skip to main content&#8221; links for CSS disabled browsers. Unfortunately, there are [...]]]></description>
			<content:encoded><![CDATA[<p>Hell must have frozen over sometime in the past month or so.  With the newest rendition of <a href="http://www.microsoft.com">the Microsoft.com Home Page</a>, the markup actually passes W3 validation for HTML 4.01 transitional.  Further noteworthy, is that there are accessibility features in place, such as &#8220;Skip to main content&#8221; links for CSS disabled browsers.</p>
<p>Unfortunately, there are still a couple dozen CSS errors and there are still a bunch of IE-only filter tags present.  Not to mention, the javascript-required flyout menus and hidden div&#8217;s that appear onmouseover, or the in-line style attributes.  Then, there&#8217;s the image maps, the iframes, the inconsistancy of single and double quotes around attributes, camel-case classes and id&#8217;s, nested tables, nested tables holding divs that hold lists that don&#8217;t even need to be in a table or div at all, and&#8230;&#8230;.</p>
<p>I think you get the point.</p>
<p>While it&#8217;s great to see the anti-w3 gods themselves actually produce valid HTML, there&#8217;s a still a lot of poorly written code that needs to be addressed.  Perhaps the markup was the first step.  We shall only wait and see what the next rendition produces.</p>
<p>This gets me thinking though:  Perhaps they viewed their site with their new IE7 beta and realized that their site needed to be fixed in order to not fall apart in their new software offering.  Or, are we seeing a new side of the company?</p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/microsoftcom-goes-valid/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Classic ASP and AJAX</title>
		<link>http://skeymedia.com/classic-asp-and-ajax-tutorial/</link>
		<comments>http://skeymedia.com/classic-asp-and-ajax-tutorial/#comments</comments>
		<pubDate>Wed, 29 Mar 2006 07:47:16 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.skeymedia.com/programming/classic-asp-and-ajax/</guid>
		<description><![CDATA[There aren’t many tutorials on the web for Classic ASP and AJAX interfaces. Classic ASP is just about fazed out at most companies, but there are still plenty of legacy applications that use it. There is a lot of confusion about AJAX and what it is. Mainly, it is a client-side application that sends data [...]]]></description>
			<content:encoded><![CDATA[<p>There aren’t many tutorials on the web for Classic ASP and AJAX interfaces. Classic ASP is just about fazed out at most companies, but there are still plenty of legacy applications that use it. There is a lot of confusion about AJAX and what it is. Mainly, it is a client-side application that sends data to a back end parser, and thus the back-end processor can be written is anything from asp to cfm to php to old-school perl cgi’s.<br />
<span id="more-7"></span><br />
First and foremost, AJAX is VERY easy.  Get it over your head that it&#8217;s complicated because its not.</p>
<p>Now, let&#8217;s get to it.<br />
I was faced with the problem of performing a city and state look up based off entered zipcode.<br />
This is a simply database pull, but because the zipcode is like the 5th thing asked, and theres more after it, it doesn&#8217;t make sense to go through a page reload process.</p>
<p>AJAX to the rescue.</p>
<p>AJAX uses 3 &#8220;sides&#8221; to make it happen.</p>
<ul>
<li>HTML form or something along these lines</li>
<li>JS scripting to pass the http request</li>
<li>server-side script or some other processor to return data when its called.</li>
</ul>
<p>First, grab this javascript function set. This can be found on just about every AJAX app or tutorial out there. I have added some tweaks to fit our application here.</p>
<p><pre><code>
var xmlHttp;
var rootpath;

rootpath = &quot;http://path.com/to/root/location/&quot;;&nbsp;&nbsp; // be sure to change this to your URL

function getZipcode(str)
{
&nbsp;&nbsp;&nbsp;&nbsp;var url=rootpath + &quot;ziplookup.asp?zipcode=&quot; + str
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;xmlHttp=GetXmlHttpObject(stateChanged)
&nbsp;&nbsp;&nbsp;&nbsp;xmlHttp.open(&quot;GET&quot;, url , true)
&nbsp;&nbsp;&nbsp;&nbsp;xmlHttp.send(null)
}

function stateChanged()
{
&nbsp;&nbsp;&nbsp;&nbsp;if (xmlHttp.readyState==4 || xmlHttp.readyState==&quot;complete&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(&quot;citystate&quot;).innerHTML=xmlHttp.responseText
&nbsp;&nbsp;&nbsp;&nbsp;}
}

function GetXmlHttpObject(handler)
{
&nbsp;&nbsp;&nbsp;&nbsp;var objXmlHttp=null

&nbsp;&nbsp;&nbsp;&nbsp;if (navigator.userAgent.indexOf(&quot;Opera&quot;)&gt;=0)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Opera not supported...&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;if (navigator.userAgent.indexOf(&quot;MSIE&quot;)&gt;=0)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var strName=&quot;Msxml2.XMLHTTP&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (navigator.appVersion.indexOf(&quot;MSIE 5.5&quot;)&gt;=0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strName=&quot;Microsoft.XMLHTTP&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objXmlHttp=new ActiveXObject(strName)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objXmlHttp.onreadystatechange=handler
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return objXmlHttp
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch(e)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Error. Scripting for ActiveX might be disabled&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;if (navigator.userAgent.indexOf(&quot;Mozilla&quot;)&gt;=0)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objXmlHttp=new XMLHttpRequest()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objXmlHttp.onload=handler
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objXmlHttp.onerror=handler
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return objXmlHttp
&nbsp;&nbsp;&nbsp;&nbsp;}
} 
</code></pre></p>
<p>And the form (x)html:</p>
<p><pre><code>
&lt;form id=&quot;frmdefault&quot;&gt;

&lt;tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;txtright&quot;&gt;Zipcode:&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;txtleft&quot;&gt;&lt;input name=&quot;zipcode&quot; type=&quot;text&quot; id=&quot;zipcode&quot; size=&quot;6&quot; maxlength=&quot;5&quot; onkeyup=&quot;getZipcode(this.value)&quot; value=&quot;&lt;%=request.cookies(&quot;OD&quot;)(&quot;zipcode&quot;)%/&gt;&quot; /&gt;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;txtright&quot; valign=&quot;bottom&quot;&gt;City / State:&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;txtleft&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;citystate&quot;&gt;&lt;span class=&quot;hilite&quot;&gt;(Enter Zip Code First)&lt;/span&gt;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;citystate2&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input class=&quot;hilite&quot; type=&quot;text&quot; id=&quot;city&quot; name=&quot;city&quot; maxlength=&quot;50&quot; size=&quot;15&quot; value=&quot;&lt;%= request.cookies(&quot;OD&quot;)(&quot;city&quot;) %/&gt;&quot; /&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input class=&quot;hilite&quot; type=&quot;text&quot; id=&quot;state&quot; name=&quot;state&quot; maxlength=&quot;2&quot; size=&quot;3&quot; value=&quot;&lt;%= request.cookies(&quot;OD&quot;)(&quot;state&quot;) %/&gt;&quot; /&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
&lt;/form&gt;
</code></pre></p>
<p>Obviously, that would be a part of the larger table you are working with that has the name, address, and so on above it.</p>
<p>Notice the onkeyup command on the zipcode input box? When you release a key, it initiates the AJAX process. In our case, it calls ziplookup.asp and passes in &#8220;this.value&#8221; or, the entered zipcode.</p>
<p>so, what does ziplookup.asp do with it?</p>
<p><pre><code>
&lt; %

If Len(request(&quot;zipcode&quot;)) = 5 Then
&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;strCN = &quot;Provider=SQLOLEDB.1;UID=XXXXXXX;Password=XXXXXXX;Persist Security Info=False;Initial Catalog=XXXXXXXX;Data Source=sqlbox1&quot;

&nbsp;&nbsp;&nbsp;&nbsp;Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;Conn.open strCN

&nbsp;&nbsp;&nbsp;&nbsp;dim rst,bool,myval,citylist, statelist

&nbsp;&nbsp;&nbsp;&nbsp;citylist = &quot;&quot;
&nbsp;&nbsp;&nbsp;&nbsp;statelist = &quot;&quot;

&nbsp;&nbsp;&nbsp;&nbsp;set rst=server.CreateObject(&quot;adodb.recordset&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sSQL =&nbsp;&nbsp;&nbsp;&nbsp;&quot;SELECT distinct city FROM [ZipCodes] where zip = &#039;&quot;&amp; request(&quot;zipcode&quot;) &amp;&quot;&#039;&quot;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set rst = Server.CreateObject(&quot;ADODB.Recordset&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.ActiveConnection = conn
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.open sSQL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if not rst.eof Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;citylist = citylist &amp; &quot;&lt;option value=&quot;&quot;&quot;&quot;&gt;Select City&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;citylist = citylist &amp; &quot;&lt;option value=&quot;&quot;&quot;&quot;&gt;---------------&lt;/option&gt;&quot;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;While Not rst.eof
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;citylist = citylist &amp; &quot;&lt;option value=&quot;&quot;&quot;&amp; rst(0) &amp;&quot;&quot;&quot;&gt;&quot;&amp; rst(0) &amp;&quot;&lt;/option&gt;&quot; &amp; VbCrLf
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.movenext
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wend

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;citylist = &quot;&lt;select onchange=&quot;&quot;fillcity(this.value);&quot;&quot; name=&quot;&quot;selcity&quot;&quot;&gt;&quot;&amp; VbCrLf &amp; citylist &amp;&quot;&lt;/select&gt;&quot;&amp; VbCrLf
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.write citylist

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot;&lt;span class=&#039;hilite&#039;&gt;No Record of this Zip&lt;/span&gt;&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sSQL =&nbsp;&nbsp;&nbsp;&nbsp;&quot;SELECT distinct state FROM [ZipCodes] where zip = &#039;&quot;&amp; request(&quot;zipcode&quot;) &amp;&quot;&#039;&quot;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set rst = Server.CreateObject(&quot;ADODB.Recordset&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.ActiveConnection = conn
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.open sSQL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if not rst.eof Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statelist = statelist &amp; &quot;&lt;option value=&quot;&quot;&quot;&quot;&gt;Select State&lt;/option&gt;&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statelist = statelist &amp; &quot;&lt;option value=&quot;&quot;&quot;&quot;&gt;---------------&lt;/option&gt;&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;While Not rst.eof
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statelist = statelist &amp; &quot;&lt;option value=&quot;&quot;&quot;&amp; rst(0) &amp;&quot;&quot;&quot;&gt;&quot;&amp; rst(0) &amp;&quot;&lt;/option&gt;&quot; &amp; VbCrLf
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.movenext
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wend

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statelist = &quot;&lt;select onchange=&quot;&quot;fillstate(this.value);&quot;&quot; name=&quot;&quot;selstate&quot;&quot;&gt;&quot;&amp; VbCrLf &amp; statelist &amp;&quot;&lt;/select&gt;&quot;&amp; VbCrLf
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.write statelist

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot;&quot;&nbsp;&nbsp;&nbsp;&nbsp;&#039;no need to echo is out twice...
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end If

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set rst = nothing
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set conn = Nothing

Else
&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot;&lt;span class=&#039;hilite&#039;&gt;Enter all 5 digits&lt;/span&gt;&quot;
End if

%&gt;
</code></pre></p>
<p>The first thing we do is to check if the entered value is 5 digits. there is no use putting extra server load on the DB for something that will never be useful. So, we wait until there&#8217;s been 5 digits entered in the input box, then we run through our query.</p>
<p>Since there are more than 1 city with similar zip codes, and the possibility that a zipcode might NOT be in my table that i found on the net somewhere&#8230;. I have given the option to enter in free-form as well. Selecting the drop down will auto populate the input for city and state.</p>
<p>That&#8217;s where our onchange functions come in handy.</p>
<p>Make sure you have your form id&#8217;ed correctly:</p>
<p><pre><code>
&lt;form id=&quot;frmdefault&quot;&gt;
&lt;/form&gt;</code></pre></p>
<p>else, the DOM scripting won&#8217;t work.</p>
<p><pre><code>
function fillstate(str) {
&nbsp;&nbsp;&nbsp;&nbsp;var theform = document.getElementById(&quot;frmdefault&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;theform.state.value = str;
}

function fillcity(str) {
&nbsp;&nbsp;&nbsp;&nbsp;var theform = document.getElementById(&quot;frmdefault&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;theform.city.value = str;
}
</code></pre></p>
<p>Also, old browsers don&#8217;t support these techniques, so keep this in mind. I built this in an all IE6 environment, so i don&#8217;t have to worry about browser differences.</p>
<p>The onkeyup will fail if JS is disabled, so its good to have a &#8220;graceful degradation&#8221; option a well, be it a button or other method to get the data back to the form&#8211; even if it requires a page load.</p>
<p>Well, there you have it. A nice and easy classic ASP AJAX example.</p>
<p>Get coding =0</p>
<p>Source:<br />
<a id="p55" href="http://www.skeymedia.com/wp-content/uploads/2007/05/asp_ajax_skeymedia.zip" title="ASP-AJAX-SOURCE">asp_ajax_skeymedia.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skeymedia.com/classic-asp-and-ajax-tutorial/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
