<?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>UseStrict Consulting</title>
	<atom:link href="http://usestrict.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://usestrict.net</link>
	<description>Professional IT Solutions &#38; Training</description>
	<lastBuildDate>Sat, 07 Jan 2012 14:05:03 +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>Why Invest In Your Website?</title>
		<link>http://usestrict.net/2012/01/why-invest-in-your-website/</link>
		<comments>http://usestrict.net/2012/01/why-invest-in-your-website/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 22:00:34 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=1264</guid>
		<description><![CDATA[It&#8217;s not that rare to hear someone claim that the look of your website isn&#8217;t the focal point of having one. While this is true &#8211; content is crucial, as even the worst-looking websites in the world can thrive if the content is good enough. The catch? Most of them can&#8217;t. Your website is your [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not that rare to hear someone claim that the look of your website isn&#8217;t the focal point of having one. While this is true &#8211; content is crucial, as even the worst-looking websites in the world can thrive if the content is good enough.</p>
<p>The catch? Most of them can&#8217;t.</p>
<p>Your website is your identity, and if it looks horrendous when it loads, the likelihood is that someone will make a snap judgement about your content, your services and your willingness to put effort into your online presence. This sounds harsh, but realistically, companies should have been investing in high-quality websites ten years ago. In the second decade into the new millennium, there&#8217;s no excuse.</p>
<p>So what makes a good website, and how do you invest in one? For starters, you&#8217;ll find that user experiences are going to improve when everything is neat, clean, well-organised and easy to use. Whether you&#8217;re running Amazon or <a href="http://www.o2.co.uk/broadband/" target="_blank">o2.co.uk</a>, your users need to be able to do whatever they want (within the bounds of the site&#8217;s purpose and their user privileges). If they can&#8217;t, they&#8217;ll simply go somewhere they can.</p>
<p>Investing in your website is simple &#8211; hire good web developers, make sure your servers are high-quality and never prone to more than .1% downtime, and hire some staff to run the site, if you&#8217;re a large enough company. A good team of staff will be comprised of a web administrator, someone on content, someone promoting the site (you can combine these last two roles, if you wish), and someone working on helping users who may have any queries.</p>
<p>Lastly, think of your website as the modern equivalent of a shop front. If it looks like something years out of date, without a door handle and with all the products lacking price tags, then you&#8217;re going to run into trouble. So keep everything clean and appealing, and it&#8217;s going to be a lot easier to generate a client/consumer base that appreciates and is loyal to your dedication to your and their online presence.</p>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2012/01/why-invest-in-your-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clients</title>
		<link>http://usestrict.net/clients/</link>
		<comments>http://usestrict.net/clients/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 19:11:04 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
		
		<guid isPermaLink="false">http://usestrict/?page_id=1099</guid>
		<description><![CDATA[A few of our past and current clients. Click on the Logos to find out more.]]></description>
			<content:encoded><![CDATA[<p>A few of our past and current clients. Click on the Logos to find out more.</p>
<style type="text/css">
#clients tr, #clients td {vertical-align:middle; text-align:center}
</style>
<table id="clients">
<tbody>
<tr>
<td width="154"><a href="http://usestrict.net/wp-content/uploads/2011/12/ibm-logo.png"><img class="size-thumbnail wp-image-1141 alignnone" title="ibm-logo" src="http://usestrict.net/wp-content/uploads/2011/12/ibm-logo-150x150.png" alt="" width="150" height="150" /></a></td>
<td width="104"><a href="http://usestrict.net/wp-content/uploads/2011/12/sitesell.jpg"><img class="alignnone size-full wp-image-1142" title="sitesell" src="http://usestrict.net/wp-content/uploads/2011/12/sitesell.jpg" alt="" width="100" height="102" /></a></td>
<td width="100"><a href="http://usestrict.net/wp-content/uploads/2011/12/cirque-logo.jpg"><img class="alignnone size-thumbnail wp-image-1143" title="cirque-logo" src="http://usestrict.net/wp-content/uploads/2011/12/cirque-logo-150x150.jpg" alt="" width="150" height="150" /></a></td>
</tr>
<tr>
<td width="148"><img class="alignnone" title="Armquip" src="http://armquip.ca/images/header/logo.png" alt="" width="150" height="57" /></td>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/jbhairstock.png"><img class="alignnone size-thumbnail wp-image-1144" title="jbhairstock" src="http://usestrict.net/wp-content/uploads/2011/12/jbhairstock-150x150.png" alt="" width="150" height="150" /></a></td>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/logo_EVO.gif"><img class="alignnone size-thumbnail wp-image-1145" title="logo_EVO" src="http://usestrict.net/wp-content/uploads/2011/12/logo_EVO-150x125.gif" alt="" width="150" height="125" /></a></td>
</tr>
<tr>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/msurlamontagne_logo.jpg"><img class="alignnone size-thumbnail wp-image-1146" title="msurlamontagne_logo" src="http://usestrict.net/wp-content/uploads/2011/12/msurlamontagne_logo-150x150.jpg" alt="" width="150" height="150" /></a></td>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/logo_bo-optik.png"><img class="alignnone size-thumbnail wp-image-1147" title="logo_bo-optik" src="http://usestrict.net/wp-content/uploads/2011/12/logo_bo-optik-150x117.png" alt="" width="150" height="117" /></a></td>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/adm_small.png"><img class="alignnone size-thumbnail wp-image-1149" title="adm_small" src="http://usestrict.net/wp-content/uploads/2011/12/adm_small-150x107.png" alt="" width="150" height="107" /></a></td>
</tr>
<tr>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/logo_jungle-eyewear.png"><img class="alignnone size-thumbnail wp-image-1150" title="logo_jungle-eyewear" src="/wp-content/uploads/2011/12/logo_jungle-eyewear-150x107.png" alt="" width="150" height="107" /></a></td>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/markie_logo.jpg"><img class="alignnone size-full wp-image-1151" title="markie_logo" src="http://usestrict.net/wp-content/uploads/2011/12/markie_logo.jpg" alt="" width="44" height="38" /></a></td>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/hobbyworx.png"><img class="alignnone size-thumbnail wp-image-1153" title="hobbyworx" src="/wp-content/uploads/2011/12/hobbyworx-150x126.png" alt="" width="150" height="126" /></a></td>
</tr>
<tr>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/fraggasm_logo.png"><img class="alignnone size-thumbnail wp-image-1154" title="fraggasm_logo" src="/wp-content/uploads/2011/12/fraggasm_logo-150x73.png" alt="" width="150" height="73" /></a></td>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/swaggasm_logo.png"><img class="alignnone size-thumbnail wp-image-1155" title="swaggasm_logo" src="/wp-content/uploads/2011/12/swaggasm_logo-150x102.png" alt="" width="150" height="102" /></a></td>
<td><a href="http://usestrict.net/wp-content/uploads/2011/12/math_logo.gif"><img class="alignnone size-thumbnail wp-image-1156" title="math_logo" src="/wp-content/uploads/2011/12/math_logo-150x128.gif" alt="" width="150" height="128" /></a></td>
</tr>
<tr>
<td colspan="3"><a href="http://usestrict.net/wp-content/uploads/2011/12/ef_logo.png"><img class="alignnone size-thumbnail wp-image-1157" title="ef_logo" src="/wp-content/uploads/2011/12/ef_logo-150x150.png" alt="" width="150" height="150" /></a></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/clients/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Services</title>
		<link>http://usestrict.net/services/</link>
		<comments>http://usestrict.net/services/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 17:40:52 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
		
		<guid isPermaLink="false">http://usestrict/?page_id=1119</guid>
		<description><![CDATA[At UseStrict Consulting we offer the following services: Web Development Whether you have an old website that needs updating, want a shiny new look for your company on the web, or need an e-commerce store, we can help you out. We will analyze your requirements and develop solutions that best match your budget. We specialize [...]]]></description>
			<content:encoded><![CDATA[<p>At UseStrict Consulting we offer the following services:</p>
<h2><a name="web_development">Web Development</a></h2>
<p>Whether you have an old website that needs updating, want a shiny new look for your company on the web, or need an e-commerce store, we can help you out. We will analyze your requirements and develop solutions that best match your budget.</p>
<p>We specialize in websites using frameworks such as WordPress (both as blog and as Content Management System) and Codeigniter, as well as pure PHP. Although we avoid starting new Web projects in Perl, we will be more than happy to maintain your legacy Perl application or website.</p>
<hr />
<h2><a name="intranets"></a>Intranet/Extranet Applications</h2>
<p>Sometimes just having a website isn&#8217;t enough. We&#8217;ve developed all kinds of administrative systems over the years. A few examples are: a student central for a language school, tuition tracking software, a web-based chat application, support ticket tracking software, a data synchronization tool, a content scheduler, and many many more. Let us know what you need and we&#8217;ll surely deliver!</p>
<hr />
<h2><a name="third_party"></a>Customization of Third Party Software</h2>
<p>If it&#8217;s written in PHP or Perl, we can handle it. Just let us know what kinds of changes you need! Some software we&#8217;ve customized over the years include OSTicket, SiteBuildIt, Codeigniter, WordPress, Zen-Cart, and Magento.</p>
<hr />
<h2><a name="training"></a>Weekend Training Workshops</h2>
<p>With almost 20 years of training experience, we can teach you all you need to know about web programming and Linux system administration. We give weekend workshops on Perl 5, PHP 5, HTML, SQL (MySQL), CSS, Javascript, Perl for system administration, and Linux S.A. Contact us to book your next training!</p>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Community</title>
		<link>http://usestrict.net/community/</link>
		<comments>http://usestrict.net/community/#comments</comments>
		<pubDate>Sat, 17 Dec 2011 20:19:06 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
		
		<guid isPermaLink="false">http://usestrict/?page_id=1025</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/community/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Launching CronBlocks.com &#8211; Scheduled content for your website</title>
		<link>http://usestrict.net/2011/08/cronblocks-com-scheduled-content-for-your-website/</link>
		<comments>http://usestrict.net/2011/08/cronblocks-com-scheduled-content-for-your-website/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 03:25:44 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[content management system]]></category>
		<category><![CDATA[content scheduling]]></category>
		<category><![CDATA[geo-location]]></category>
		<category><![CDATA[site builder]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=1006</guid>
		<description><![CDATA[It&#8217;s been a while since my last post, but it&#8217;s been for a good cause. This week I launched CronBlocks.com, an app that allows you to insert content on a web-page according to a given schedule. Here&#8217;s how it works: Go to www.cronblocks.com and click on Plans to sign up &#8211; there&#8217;s a free plan [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since my last post, but it&#8217;s been for a good cause. This week I launched CronBlocks.com, an app that allows you to insert content on a web-page according to a given schedule.</p>
<p>Here&#8217;s how it works:</p>
<ol>
<li>Go to <a href="http://www.cronblocks.com" target="_blank">www.cronblocks.com</a> and click on Plans to sign up &#8211; there&#8217;s a free plan if you just want to see how it works. Check out the premium plans once you&#8217;re satisfied it&#8217;s what you need.</li>
<li>After signing up, and activating your account (you&#8217;ll get an activation email), click on the Channels link. The Channels allow you to control where on your page you want the content to appear.</li>
<li>Configure your channel to run by server (EDT) or client time &#8211; I recommend client time since you&#8217;ll probably be receiving people from across several different time zones.</li>
<li>You can choose to copy the JS snippet at this time, or leave it for later &#8211; it&#8217;s the JS snippet that you&#8217;ll use on your website to show the content</li>
<li>Once you have the channel set up, you can create your scheduled blocks for that channel. Blocks are the actual content that&#8217;ll show on your page. You can create as many schedules for a block as you want/need &#8211; either by months/days or by day-of-week. And you get to set the time you want them to show, too.</li>
<li>If you have multiple blocks to show that overlap a given time slot, you can set them to have different priorities (weight). Higher weights trump lower ones. Think of it as stack, with heavier items being served first. Overlapping items with same weight will be picked randomly.</li>
</ol>
<p>And that&#8217;s all there is to it. Your site will show whatever block is set up for that given timestamp.</p>
<p>What uses do you have for this? Well, for starters, you can segment your ads by time &#8211; sell your &#8220;prime time&#8221; for a higher price than other times (for those of you who don&#8217;t use ad networks). You can also include some JS in your block to make it refresh every 15 seconds or so. Basically, your imagination is the limit.</p>
<p>I&#8217;ll create new posts in the future with more examples. In the meantime, here&#8217;s a test block for you.</p>
<p><script type="text/javascript">
    (function(){
        document.write('<script type="text/javascript" src="http://cb1.cronblocks.com/js/content.js?c=3&amp;t='+(Math.floor(new Date().getTime()/1000))+'&amp;s=client"><\/script>');
    })();
</script></p>
<p>Cheers,<br />
Vinny</p>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2011/08/cronblocks-com-scheduled-content-for-your-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Safari shows a blank page</title>
		<link>http://usestrict.net/2011/03/safari-shows-a-blank-page/</link>
		<comments>http://usestrict.net/2011/03/safari-shows-a-blank-page/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 21:23:55 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[all sorts]]></category>
		<category><![CDATA[background image]]></category>
		<category><![CDATA[blank page]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[close]]></category>
		<category><![CDATA[complex solutions]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[end]]></category>
		<category><![CDATA[FireFox]]></category>
		<category><![CDATA[Googled]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Interface]]></category>
		<category><![CDATA[issue]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[lt]]></category>
		<category><![CDATA[none]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[Safari]]></category>
		<category><![CDATA[script tag]]></category>
		<category><![CDATA[script type]]></category>
		<category><![CDATA[something]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[text javascript]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[type]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=992</guid>
		<description><![CDATA[Safari shows a blank page, no content, due to missing comment close in JavaScript.]]></description>
			<content:encoded><![CDATA[<p>I just ran into something odd and found all sorts of complex solutions (none of which worked for me), so I decided to post this case.</p>
<p>I&#8217;m creating a new version of an interface at work and tested with FireFox during development. When I opened it in Safari, all I got was the background image. No content at all. I Googled and several people reported having the same problem and said that clearing the cache would do the trick. It did not.</p>
<p>In the end, the issue was a missing &#8216;&#8211;&gt;&#8217; inside a <code>script</code> tag.</p>
<pre class="brush:javascript">&lt;script type="text/javascript"&gt; &lt;!-- // open a comment for older browsers - is this actually required still??
/* lots of JS here */

// There should be a close comment (--&gt;)  here!
&lt;/script&gt;</pre>
<p>Safari, not finding the closing comment tag, simply considered all of the HTML to be commented out.</p>
<p>I hope this helps!</p>
<p>&nbsp;</p>
<h3>Book Suggestions:</h3>
<p>&nbsp;</p>
<div>
<script type="text/javascript">
    (function(){
        document.write('<script type="text/javascript" src="http://cb1.cronblocks.com//js/content.js?c=14&#038;t='+(Math.floor(new Date().getTime()/1000))+'&#038;s=client"><\/script>');
    })();
</script>
</div>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2011/03/safari-shows-a-blank-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m now on Suite101.com!</title>
		<link>http://usestrict.net/2009/09/im-now-on-suite101com/</link>
		<comments>http://usestrict.net/2009/09/im-now-on-suite101com/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 21:58:23 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=874</guid>
		<description><![CDATA[Hey folks! I&#8217;d like to announce that I&#8217;ve debuted on suite101.com. My first article there was how to optimize your job hunting using RSS feeds. Check out the article here.]]></description>
			<content:encoded><![CDATA[<p>Hey folks!</p>
<p>I&#8217;d like to announce that I&#8217;ve debuted on suite101.com. My first article there was how to optimize your job hunting using RSS feeds. </p>
<p><a href="http://job-search.suite101.com/article.cfm/optimize_your_search_for_new_jobs" target="_blank">Check out the article here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2009/09/im-now-on-suite101com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Ajax</title>
		<link>http://usestrict.net/2009/08/introduction-to-ajax/</link>
		<comments>http://usestrict.net/2009/08/introduction-to-ajax/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 21:56:08 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=840</guid>
		<description><![CDATA[Introduction to Ajax, Ajax how-to]]></description>
			<content:encoded><![CDATA[<p>In this article, I provide an explanation of Ajax with a historical introduction. If you are eager to start seeing the code, please scroll down.</p>
<p>&nbsp;</p>
<h3>What’s Ajax?</h3>
<p>&nbsp;</p>
<p>Ajax stands for <em>Asynchronous Javascript And XML</em>. It’s a way to call back-end scripts asynchronously – that is, without impacting user experience/flow. Basically, you don&#8217;t even see the cursor become an hourglass or whatever other &#8220;waiting/processing&#8221; icon your system uses. It&#8217;s not a language, but a technique. As for back-end scripts, you can use whatever you feel more comfortable with: PHP, Perl, Java, JSP, Shell, C, etc. The way to choose which technology to use as back-end is not outside the scope of this article.</p>
<p>&nbsp;</p>
<h3>Historical approach for calling back-end apps</h3>
<p>&nbsp;</p>
<p>Throughout web-development history, the very first way used to achieve back-end processing followed by front-end display was to create a form and set the back-end script as the action to that form. Upon submission, the form fields would be sent to the back-end script as a series of special environment variables, which would then be handled by the programmed logic. The back-end output would be displayed on the screen (either the same page/frame or a different page/frame, depending on the target attribute of the form).</p>
<p>The catch 22 of this approach is that if you want to present another form after processing, that form must be produced by the back-end script, which leads to maintenance mayhem – to add or remove a field, you have to do so in both the original HTML and in the HTML of the back-end script.</p>
<p><span id="more-840"></span></p>
<p>&nbsp;</p>
<h3>Hidden IFRAMES and Javascript to the rescue</h3>
<p>&nbsp;</p>
<p>The natural evolution of the regular form submission was to avoid having to generate HTML from the back-end script. A technique that I eventually came up with (had never seen it before, but it was probably already out there) prior to adhering to Ajax was using a hidden IFRAME as target to a simple form containing an <em>action_cd</em> field and a <em>data</em> field. There would not be a regular submit button, but a set of input elements with <em>onclick</em> or <em>onchange</em> events and a regular (non-submit) button at the end. </p>
<p>In this approach, Javascript did all the work – when the user clicked the pseudo-submit button, an <em>onclick</em> event would read all the input fields and join them like a regular HTTP query (<code>field1=val1&#038;field2=val2</code>…). The <em>action_cd</em> value would be dynamically evaluated and the back-end script would receive the data string and action code and process it. Javascript would perform the submission when, say, a value of a drop-down field was selected, and the output would be a series of dynamically generated Javascript commands inside the IFRAME. Those commands would manipulate the user’s form (e.g. Auto-populate a &#8220;state&#8221; drop-down after selecting a &#8220;country&#8221; value). </p>
<p>Although this approach successfully handled the no-longer-need to submit and reload a form, it still had 2 main downsides: generating and maintaining Javascript code is not a simple task (especially due to having to escape quotes), and the whole procedure was still synchronous – you could see the hourglass, browser process bars, clicking sounds (IE), etc. It&#8217;s much better user experience, but still not the real deal, seamless/transparent back-end processing.</p>
<p>&nbsp;</p>
<h3>The XmlHttpRequest object</h3>
<p>&nbsp;</p>
<p>Javascript back-end calls are made possible thanks to the <em>XmlHttpRequest</em> object that most modern browsers now support. For IE 6 and older, it is done through an ActiveXObject. </p>
<p>&nbsp;</p>
<h3>Javascript code to initialize Ajax object</h3>
<p>&nbsp;</p>
<pre class="brush:javascript">

var xmlHttp; // global variable. It’s important for later on

function GetXmlHttpObject(){

      if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
      }

      if (window.ActiveXObject){
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
      return null;
}
</pre>
<p>It&#8217;s important to have a global variable in which to assign the XMLHttpRequest object, since this technique has its shortcomings when dealing with passing variables around. We&#8217;ll understand that better shortly. The function checks for the existence of <strong>window.XMLHttpRequest</strong> which is used in IE7 (finally, it complies to standards!), Firefox, and other non IE browsers, and checks for <strong>window.ActiveXObject</strong> existence for IE6 and 5. I’m not sure if this works on IE4 – it probably does not, but hopefully IE4 is already in extinction. If neither checks work, it returns null, which will be handled in the function calling the XMLHttpObject.</p>
<p>&nbsp;</p>
<h3>Making Synchronous Ajax calls (GET method)</h3>
<p>&nbsp;</p>
<p>Although the hype of Ajax is due to the &#8220;Asynchronosity&#8221; of the technique, it is also capable of making synchronous calls. Synchronous calls are important in cases where you don&#8217;t want to allow the user to do something while the back-end is checking a previous action, but also don&#8217;t want to have to submit the whole form.</p>
<pre class="brush:javascript">

function synch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”;

      // Synchronous call
      xmlHttp.open("GET",url,false); // "false" means asynchronous = false
      xmlHttp.send(null);

      // the code above does the back-end call. Now we handle the response
      // this function continues further down in the tutorial

}
</pre>
<p>Ajax calls can be done using GET or POST methods. I recommend GET methods for small queries, POST for large ones. There used to be a limit of 255 characters on URL fields – not sure if a) this is still true; b) this could apply to these Ajax techniques.</p>
<p>The call to the back-end is done by 2 commands: <strong>xmlHttp.open(Method,url,async)</strong>, and the <strong>xmlHttp.send(null)</strong> calls. For POST method, this is a little different, so we’ll stick to GET calls for the time being.</p>
<p>&nbsp;</p>
<h3>Handling back-end reply</h3>
<p>&nbsp;</p>
<p><em>Asynchronous Javascript And XML</em> isn&#8217;t the perfect name for Ajax. It should be more like Aja<strong>R</strong>, where R stands for Reply. The reason is because the reply can be either an XML structure or a plain text. We use <strong>xmlHttp.responseXML.documentElement</strong> if we’re handling XML, or a plain <strong>xmlHttp.responseText</strong> for plain text. Actually, we can use the latter for XML as well, especially when debugging the code (when you want to pop up the XML reply).</p>
<p>We use a try/catch block to capture any errors:</p>
<pre class="brush:javascript">
function synch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”;

      // Synchronous call

      xmlHttp.open("GET",url,false); // “false” means asynchronous = false
      xmlHttp.send(null);

      // the code above does the back-end call. Now we handle the response
      try {            

            alert("Ajax Response: n"+xmlHttp.responseText); // Just pop-up the reply
            return false;
      }
      catch(e) {
            alert(e); // if error, show it as a pop-up
            return false;
      }
}
</pre>
<p>&nbsp;</p>
<p>To handle the  reply as XML, you need to a) make sure your back-end script outputs an XML structure, and b), replace xmlHttp.reponseText for xmlHttp.responseXML.documentElement.</p>
<p>&nbsp;</p>
<pre class="brush:javascript">
// Just the try/catch block changed        

       try {
              data = xmlHttp.responseXML.documentElement;
        }
        catch(e) {
               alert(e);
               return false;
        }
</pre>
<p>The <code>data</code> variable now holds a DOM object of the XML structure. To access its elements, we use DOM functions. </p>
<p>Example XML structure:</p>
<pre class="brush:xml">
&lt;OUT&gt;
      &lt;STATUS&gt;Success&lt;/STATUS&gt;
      &lt;MSG type="some_type"&gt;This is a test message&lt;/MSG&gt;
&lt;/OUT&gt;
</pre>
<p>Accessing Example XML through DOM:</p>
<pre class="brush:javascript">

      // gets the Success text
      var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue;

      // Assign MSG object to msg variable
      var msg = data.getElementsByTagName(‘MSG’)[0]; 

      // gets the attribute “type”
      var msg_type = msg.getAttribute(‘type’); 

      // gets the text inside the MSG node
      var msg_text = msg.childNodes[0].nodeValue;
</pre>
<p>&nbsp;</p>
<h3>Putting it all together</h3>
<p>&nbsp;</p>
<pre class="brush:javascript">
function synch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”; 

      // Synchronous call
      xmlHttp.open("GET",url,false); // "false" means asynchronous = false
      xmlHttp.send(null);

      // the code above does the back-end call. Now we handle the response

      try {
            data = xmlHttp.responseXML.documentElement;
       }
       catch(e) {
             alert(e);
             return false;
       }

      // gets the Success text
      var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue; 

      // Assign MSG object to msg variable
      var msg = data.getElementsByTagName(‘MSG’)[0]; 

      // gets the attribute “type”
      var msg_type = msg.getAttribute(‘type’); 

      // gets the text inside the MSG node
      var msg_text = msg.childNodes[0].nodeValue;
      alert("Got the following backend reply: " + msg_status + "n" + msg + "n" + msg_type + "n" + msg_text);

      return true;
}
</pre>
<p>&nbsp;</p>
<h3>Making Asynchronous Ajax calls (GET method)</h3>
<p>&nbsp;</p>
<p>We saw on page 2 that what controls synchronicity of the Ajax call is the true/false value in the <code>open()</code> command. However, we also need changes in the way we handle the reply. We do that by setting <strong><em>onreadystatechange</em></strong> property on the xmlHttp object.</p>
<p> OnReadyStateChange should be a function that will check the <em><strong>readyState</strong></em> attribute of the xmlHttp object.</p>
<p>&nbsp;</p>
<h3>Understanding readyState</h3>
<p>&nbsp;</p>
<p>readyStates are the way Javascript controls what stage of the process the call is in. It ranges from 0 to 4, where 4 is the completed reply from the back-end script. We normally only care about readyState == 4. Here are the codes and meaning:</p>
<table>
<tr>
<td><strong>Value</strong></td>
<td><strong>State</strong></td>
</tr>
<tr>
<td>0</td>
<td>Uninitialized</td>
</tr>
<tr>
<td>1</td>
<td>Loading</td>
</tr>
<tr>
<td>2</td>
<td>Loaded</td>
</tr>
<tr>
<td>3</td>
<td>Interactive</td>
</tr>
<tr>
<td>4</td>
<td>Complete</td>
</tr>
</table>
<p>&nbsp;</p>
<h3>Setting onreadystatechange</h3>
<p>&nbsp;</p>
<p><code>onreadystatechange</code> can be assigned a anonymous <code>function() {  }</code> block, or a named function. Just be careful with function parameters – to this day, I have not been able to pass any parameters to the functions set to <code>onreadystatechange</code>. Hence the need for some global variables in play.</p>
<p>Let&#8217;s copy over our <code>sync_call()</code> function and make it <code>Async_call()</code></p>
<pre class="brush:javascript">
function Asynch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”;

      // onreadystatechange must be set BEFORE making the call

      // it takes the response handling code that we had in the sync_call() previously
      xmlHttp.onreadystatechange = function() {

            if (xmlHttp.readyState == 4) { // Complete

                  // Now we handle the response within the onreadystatechange
                  try {
                        data = xmlHttp.responseXML.documentElement;
                  }
                  catch(e) {
                        alert(e);
                        return false;
                  }

                  // gets the Success text
                  var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue; 

                  // Assign MSG object to msg variable
                  var msg = data.getElementsByTagName(‘MSG’)[0]; 

                  // gets the attribute "type"
                  var msg_type = msg.getAttribute('type'); 

                  // gets the text inside the MSG node
                  var msg_text = msg.childNodes[0].nodeValue;

                  alert("Got the following backend reply: " + msg_status + "n" + msg + "n" + msg_type + "n" + msg_text);
                  return true;
            }

      }; // don’t forget the ';' at the end of the function() {} block!!

      // Asynchronous call
      xmlHttp.open("GET",url,true); // 'true' means asynchronous = true
      xmlHttp.send(null);
}
</pre>
<p>&nbsp;</p>
<p>As mentioned before, you can separate the anonymous function assignment into a named function. The good side of this is that your functions get more manageable, but the downside is that you might need global variables in order to share values between the main function and the <code>onreadystatechange,/code> function.</p>
<p>&nbsp;</p>
<pre class="brush:javascript">
function Asynch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”; 

      // onreadystatechange must be set BEFORE making the call

      // it takes the response handling code that we had in the sync_call previously
      xmlHttp.onreadystatechange = handlerfunction; // See separate function below    

      // Asynchronous call
      xmlHttp.open("GET",url,true); // “true” means asynchronous = true
      xmlHttp.send(null);
}

function handlerfunction() {

      if (xmlHttp.readyState == 4) { // Complete – must be global xmlHttp variable

            // Now we handle the response within the onreadystatechange
            try {
                  data = xmlHttp.responseXML.documentElement;
            }
            catch(e) {
                  alert(e);
                  return false;
            }

             // gets the Success text
            var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue; 

            // Assign MSG object to msg variable
            var msg = data.getElementsByTagName(‘MSG’)[0]; 

            // gets the attribute “type”
            var msg_type = msg.getAttribute(‘type’); 

            // gets the text inside the MSG node
            var msg_text = msg.childNodes[0].nodeValue;

            alert("Got the following back-end reply: " + msg_status + "n" + msg + "n" + msg_type + "n" + msg_text);
            return true;

      }
}
</pre>
<p>&nbsp;</p>
<h3>Parsing forms to create the GET/POST strings</h3>
<p>&nbsp;</p>
<p>Since we are not submitting the form with the usual submit button, we have to handle building the queries ourselves. I came up with a function that mimics the way browsers handle function calls.</p>
<pre class="brush:javascript">
function build_post_string(frm) {

      var str;
      var poststr_array = [];

      if (!frm.id) {
            // assume it's a string. get the form object
            frm = document.getElementById(frm);
      }

      for (i=0;i&lt;frm.elements.length;i++){

            var elem = frm.elements[i];

            if (!elem.id) {
                  // skip any fields that don't have IDs
                  continue;
            }

            if (elem.type == 'radio' || elem.type == 'checkbox') {

                  // only grab radio buttons and checkboxes that are checked
                  if (!elem.checked) {
                        continue;
                  }

            }            

            // get select values
            if (elem.nodeName.match(/SELECT/i) &#038;&#038; elem.multiple) {

                  var sel_array = [];

                  for (var o=0;o&lt;elem.options.length;o++) {

                        if (elem.options[o].selected) {
                              sel_array[sel_array.length] = elem.id+"="+elem.options[o].value;
                        }

                  }

                  var sel_str = sel_array.join('&#038;');

                  // build key/value pairs for SELECTs
                  poststr_array[poststr_array.length] = sel_str;
            }
            else if (elem.nodeName.match(/SELECT/i)) {
                  poststr_array[poststr_array.length] = elem.id+'='+elem.options[elem.selectedIndex].value;
            }
            else {
                  // build key/value pairs for everything else
                  poststr_array[poststr_array.length] = elem.id+"="+elem.value;
            }

      }

      // build and return str
      str = poststr_array.join("&#038;");
      return str;
}
</pre>
<p>This function takes a given form by ID and iterates through all of its elements. It is important that all fields you want in the query have an ID attribute. Otherwise they will be skipped. <strong>The return from this function can be used for both GET and POST requests.</strong></p>
<p>&nbsp;</p>
<h3>Using POST method for Ajax calls</h3>
<p>&nbsp;</p>
<p>So far we saw that making GET calls is pretty straight-forward. POST calls are different in the way that they are not put in the HTTP Header, but rather in a separate packet. In order to do that, we need to set a few header variables:</p>
<pre class="brush:javascript">
function Asynch_call_with_post() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var post_str = build_post_string(‘my_form’); 

      var url = “/url/to/your/backend/script?” + post_str;

      // onreadystatechange must be set BEFORE making the call
      // it takes the response handling code that we had in the sync_call previously
      xmlHttp.onreadystatechange = function() {

            if (xmlHttp.readyState == 4) { // Complete

                   // Now we handle the response within the onreadystatechange
                   try {
                         data = xmlHttp.responseXML.documentElement;
                    }
                    catch(e) {
                         alert(e);
                         return false;
                    }

                     // gets the Success text
                     var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue; 

                      // Assign MSG object to msg variable
                     var msg = data.getElementsByTagName(‘MSG’)[0]; 

                     // gets the attribute “type”
                     var msg_type = msg.getAttribute(‘type’); 

                     // gets the text inside the MSG node
                     var msg_text = msg.childNodes[0].nodeValue;
                     alert("Got the following backend reply: " + msg_status + "n" + msg + "n" + msg_type + "n" + msg_text);
                     return true;
               }

        }; // don't forget the ';' at the end of the function() {} block

        // Asynchronous call
        xmlHttp.open('POST',url, true); // Replace "GET" with "POST"

        // Set headers
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", url.length);
        xmlHttp.setRequestHeader("Connection", "close");

        // Send the packet. Note that it’s no longer null as parameter to send
        xmlHttp.send(url);
}
</pre>
<p>&nbsp;</p>
<h3>Showing/Hiding "Processing…" messages</h3>
<p>&nbsp;</p>
<p>Since Ajax in Asynchronous mode is 100% transparent to the user, it is necessary to handle our own messages asking the user to wait until processing finishes. The simplest way to do this is by using a <code>DIV</code> element with initial display property set as none, or visibility set as hidden (the difference is that <code>visibility="hidden"</code> makes the element still occupy its space in the page, whereas <code>display="none"</code> effectively removes the element from the page and the space that it occupied).</p>
<p>Typically, I include code to show the element in the Ajax function, and code to hide it again in the <em>onreadystatechange</em> function (where readyState == 4). </p>
<pre class="brush:javascript">
        document.getElementById(‘wait_image’).display = ‘block’;
        document.getElementById(‘wait_image’).display = ‘none’;
</pre>
<p>&nbsp;</p>
<h3>Third-Party AJAX Libraries</h3>
<p>&nbsp;</p>
<p>There are several Ajax in a box libraries out there, but I am not comfortable with using them for company applications. The reason being is that Ajax is very powerful and can very well make calls to the maintainer's website to steal/capture sensitive information.  </p>
<p>Google provides Java code that generates Ajax during build – that is a typical example of us not being able to control Ajax code generated. </p>
<p>&nbsp;</p>
<h3>Testing the back-end script</h3>
<p>&nbsp;</p>
<p>There are 2 simple ways of testing the back-end script. With PHP, you can access both GET and POST variables through the <code>$_REQUEST</code> array. Perl CGI doesn’t really care if it’s GET or POST. I don’t know how JSP can handle it. With this being said, I simply have the Ajax alert the URL variable and return false. I then copy the URL variable and paste it in another window to see the output.</p>
<p>I strongly recommend debugging with Firefox – it has a handy error console and also parses the output XML or complains if it’s not built right.</p>
<p>&nbsp;</p>
<h3>Keeping IE from crashing with the XMLs</h3>
<p>&nbsp;</p>
<p>I'm pretty sure that Microsoft IE developers have some satisfaction in making web developers go crazy. That's how I felt when I started working with XML and Ajax, and although my app was working fine in Firefox, it kept crashing bad in IE. After some googling, I found out that I needed to set some headers in order to keep IE from blowing up. I already had the <code>"Content-type: text/xml"</code> header in place, but it appears that IE needs some caching control and expiry headers as well.</p>
<p>This is what I use in PHP:</p>
<pre class="brush:php">
        header("Expires: Fri, 09 Jan 1981 05:00:00 GMT");
        header("Cache-Control: no-store, no-cache, must-revalidate");
        header("Cache-Control: post-check=0, pre-check=0", FALSE); // FALSE means add this Cache-Control line instead of replacing the previous one
        header("Pragma: no-cache");
        header("Content-type: text/xml");
</pre>
<p>In Perl, setting headers is simple: just <code>print</code> them before printing any content. When you're done printing all your headers, print an empty newline to indicate where the page content will go.</p>
<p>I hope you've enjoyed this tutorial. Feel free to paste comments regarding your experience and preferences.</p>
<p>&nbsp;</p>
<h3>Book Suggestions:</h3>
<p>&nbsp;</p>
<div>
<script type="text/javascript">
    (function(){
        document.write('<script type="text/javascript" src="http://cb1.cronblocks.com//js/content.js?c=14&#038;t='+(Math.floor(new Date().getTime()/1000))+'&#038;s=client"><\/script>');
    })();
</script><br />
</script>
</div>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2009/08/introduction-to-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP+PDO+MySQL: How I&#8217;m doing it and a question&#8230;</title>
		<link>http://usestrict.net/2009/08/phppdomysql-how-im-doing-it-and-a-question/</link>
		<comments>http://usestrict.net/2009/08/phppdomysql-how-im-doing-it-and-a-question/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 12:47:18 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Update]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=832</guid>
		<description><![CDATA[Example of PHP+PDO+MySQL usage to select and update arbitrary fields. Only one prepared statement is used for updating the data.]]></description>
			<content:encoded><![CDATA[<p>I recently decided to rewrite an application that I created for an English school where I used to work, and this time I want to do it right. I chose to write it in PHP with Object Orientation in mind, and use PDO+MySQL for the DAO portion.</p>
<p>The reason for using PDO is that it&#8217;s the closest thing to the DBI that I found for PHP &#8211; and the reason for PHP is that it&#8217;s just plain simpler than using pure Perl, and I don&#8217;t have the time to learn Catalyst or some other Perl Web framework.</p>
<p>Anyway, here&#8217;s what I&#8217;m doing for the PDO portion.</p>
<p>First I created a <code>Db</code> class which is just a DB connection wrapper.</p>
<pre class="brush:php">
&lt;?php
class Db{

	public $dbh  = null;

	public function Db($db_type,$db_host,$db_user,
			         $db_pass,$db_base,$tbl_prefix){

		if ($db_type == 'mysql') { // in case I want to add oracle in the future

			$mysql_DSN = "mysql:host=".$db_host.";dbname=".$this->db_base;

			try {
				$this->dbh = new PDO($mysql_DSN, $db_user, $db_pass,
							   array(PDO::ATTR_PERSISTENT => true, PDO::ERRMODE_WARNING => true,
							         PDO::ATTR_ERRMODE => true));

			}
			catch(PDOException $e){
				$rc[msg] = $e->getMessage();
				die($rc[msg] . "  " . __LINE__);
			}

			return $this->dbh;

		}

	}

}
?&gt;
</pre>
<p>Secondly, I created the DAO classes which extend the DB. They are responsible for <code>prepare</code>&#8216;ing and <code>execute</code>&#8216;ing the queries, and returning the data. Here&#8217;s an example one (I stripped some bells and whistles in order to not confuse anyone):</p>
<pre class="brush:php">
&lt;?php
class StudentsDao extends Db {

	public $sth = array();

	// Constructor
	public function StudentsDao($db_type=NULL,$db_host=NULL,$db_user=NULL,
				  	       $db_pass=NULL,$db_base=NULL,$tbl_prefix=NULL) { // These params are to be passed to Db class

		// Connect to DB
		$this->Db($db_type,$db_host,$db_user,
			      $db_pass,$db_base,$tbl_prefix);

		// Prepares queries
		$this->sth = $this->prepare($tbl_prefix); // Look at prepare() further down

	} // end of function StudentsDao

	// Function that prepares queries
	public function prepare() {

		$sth = null; // will hold our temporary array

		// get all students
		$string = sprintf('select * from %s.%sstudents where id = ?',DB_BASE,TBL_PREFIX);	// I have these constants defined in the main page
		$sth['getStudentById'] = $this->dbh->prepare($string);

		// update Student by Id
		$string = sprintf('update %s.%sstudents
				   set field1 = ?, field2 = ?, field3 = ?
				   where id = ?',DB_BASE,TBL_PREFIX);	// Note that this table has 3 control fields (id, sys_creation_date, and sys_update_date)  prior to field1, field2, and field3 - I don't want them to be touched

		$sth['updStudentById'] = $this->dbh->prepare($string);

		return $sth;

	} // end of prepare()

	// Here we have the handlers for the queries prepared above.

	// Fetches all students
	public function getStudentById($id) {

		$s = $this->sth['getStudents'];
		$s->execute(array($id)) || die(print_r($s->errorInfo,1));
		$result = $s->fetchAll(PDO::FETCH_ASSOC);

		if (sizeof($result) == 0) {
			// no data found
			$out[err_cd] = 1;
		}
		else {
			// data was found
			$out[err_cd] = 0;
			$out[data] = $result;
		}

		return $out;

	}

	// Updates student by Id - this is a tricky one
	public function updateStudentById($data,$id){ // $data can have data regarding one or more fields

		// Populate current fields
		$fields = $this->getStudentById($id); // get current values

		// Remove unwanted fields
		$fields = array_slice($fields[data][0],3); // remove the 3 initial control fields

		// Replace with new fields
		foreach($data as $k=>$v){
			$fields[strtolower($k)] = $v;
		}
		$fields['id'] = $id;

		$s = $this->sth['updStudentById'];
		$s->execute(array_values($fields)) || die(print_r($s->errorInfo,1));
		$count = $s->rowCount();

		if ($count == 1) {
			$out[err_cd] = 0;
		}
		else {
			$out[err_cd] = -1;
		}
		$out[err_msg] = $this->status[$out[err_cd]];
		return $out;

	}
?&gt;
</pre>
<p>In the example above, you will probably frown on the fact that I&#8217;m calling <code>getStudentById()</code> at the beginning of <code>updateStudentById()</code>. It&#8217;s OK &#8211; I frown on it, too. Let me explain why I did that:</p>
<p>I wanted to be able to pass the function an associative array containing only the fields I want to update &#8211; be it only <code>field1</code>, or <code>field1</code> and <code>field2</code> and so on. But I wanted to do that against my already prepared query, and not touching any additional fields. In my application, <code>students</code> table has a BUNCH of fields. In other words, update any given field or set of fields using the single prepared statement, <strong>without</strong> having to set ALL the fields in <code>$data</code></p>
<p>My original idea was to basically, to emulate something like this:</p>
<p><code> update students set field1=field1, field2='some new value ', field3=field3 where id = 1</code></p>
<p>That would set <code>field1</code> to whatever value <code>field1</code> already had. </p>
<p><strong>Here&#8217;s the question part:<br />
Unfortunately, I couldn&#8217;t figure out how to do that using the PDO (how to bind a field name instead of a value against the <code>?</code>-mark). If you know how to do that, do leave a comment explaining how! <img src='http://usestrict.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
</strong></p>
<p>The technique shown in the example will basically pull all values from the record and populate them in the <code>$fields</code> array. The <code>array_slice()</code> is used to remove the control fields that I have in my table, and the rest gets compared against the <code>$data</code> array and if any matching fields are found in <code>$data</code>, those fields get their values assigned over the existing <code>$fields</code> values.</p>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2009/08/phppdomysql-how-im-doing-it-and-a-question/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ajax: Form fields into URL query string</title>
		<link>http://usestrict.net/2009/07/ajax-form-fields-into-url-query-string/</link>
		<comments>http://usestrict.net/2009/07/ajax-form-fields-into-url-query-string/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 09:46:20 +0000</pubDate>
		<dc:creator>vinny</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Query string]]></category>
		<category><![CDATA[URL Query]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=818</guid>
		<description><![CDATA[Javascript code to parse form fields into URL query string. To be used with Ajax sites.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quickie for you Ajax coders who need a function to parse your form fields into a URL query string. It handles input fields (text, hidden, whatever), radio and checkbox elements, and single/multiple select menus. Just make sure that all your form fields have IDs. <del>Multiple choice SELECTs get grouped by pipes (|).</del> <strong>Update:</strong>Modified multiple-choice SELECTs to work like real GETs.</p>
<pre class="brush:javascript">
function build_post_string(frm) {

	var poststr;
	var poststr_array = [];

	if (!frm.id) {
		// assume it's a string. get the form object
		frm = document.getElementById(frm);
	}

	for (i=0;i&lt;frm.elements.length;i++){

		var elem = frm.elements[i];

		if (!elem.id) {
			// skip any fields that don't have IDs
			continue;
		}

		if (elem.type == 'radio' || elem.type == 'checkbox') {
			// only grab radio buttons and checkboxes that are checked
			if (!elem.checked) {
				continue;
			}
		}

		// get select values
		if (elem.nodeName.match(/SELECT/i) &#038;&#038; elem.multiple) {
			//var sel = elem;
			var sel_array = new Array();

			for (var o=0;o&lt;elem.options.length;o++) {

				if (elem.options[o].selected) {
					sel_array[sel_array.length] = elem.id+"="+elem.options[o].value;
				}
			}

			var sel_str = sel_array.join('&#038;');

			// build key/value pairs for SELECTs
			poststr_array[poststr_array.length] = sel_str;
		}
		else if (elem.nodeName.match(/SELECT/i)) {
			poststr_array[poststr_array.length] = elem.id+'='+elem.options[elem.selectedIndex].value;
		}
		else {
			// build key/value pairs for everything else
			poststr_array[poststr_array.length] = elem.id+"="+elem.value;
		}

	}

	// build poststr
	poststr = poststr_array.join("&#038;");
	return poststr;

}
</pre>
<p>&nbsp;</p>
<h3>Book Suggestions:</h3>
<p>&nbsp;</p>
<div>
<script type="text/javascript">
    (function(){
        document.write('<script type="text/javascript" src="http://cb1.cronblocks.com//js/content.js?c=14&#038;t='+(Math.floor(new Date().getTime()/1000))+'&#038;s=client"><\/script>');
    })();
</script>
</div>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2009/07/ajax-form-fields-into-url-query-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

