<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Ask About PHP</title>
	
	<link>http://www.askaboutphp.com</link>
	<description />
	<lastBuildDate>Wed, 09 Jun 2010 07:17:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AskAboutPhp" /><feedburner:info uri="askaboutphp" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>PHP and jQuery: Submit a form without refreshing the page</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/19vZc1IEN2A/php-and-jquery-submit-a-form-without-refreshing-the-page.html</link>
		<comments>http://www.askaboutphp.com/213/php-and-jquery-submit-a-form-without-refreshing-the-page.html#comments</comments>
		<pubDate>Wed, 09 Jun 2010 06:55:39 +0000</pubDate>
		<dc:creator>Eldee</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=213</guid>
		<description><![CDATA[Lately, I&#8217;ve been chancing on quite a number of posts at various places asking about how to perform a web action without the webpage reloading/refreshing? For example, dynamically updating a list on a page without a reload or submitting a form to PHP without leaving the webpage the form sits on.
I guess this is as [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/213/php-and-jquery-submit-a-form-without-refreshing-the-page.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p>Lately, I&#8217;ve been chancing on quite a number of posts at various places asking about how to perform a web action without the webpage reloading/refreshing? For example, dynamically updating a list on a page without a reload or submitting a form to PHP without leaving the webpage the form sits on.</p>
<p>I guess this is as good a time to start branching into some posts on PHP and Javascript, or more specifically, jQuery.</p>
<p><span id="more-213"></span><br />
To be honest, I&#8217;ve never been partial to using Javascript (ie client-side programming) in my web applications, prefering instead to rely on server-side processing for all my programming needs. I guess this has to do with my frustrations of Javascript incompatibility between different browsers back in the day. However, with a javascript library (or framework) like jQuery, I&#8217;m starting to use more client-side actions to complement all the server-side PHP stuff. Here&#8217;s <a href="http://davidwalsh.name/6-reasons-to-use-javascript-libraries-frameworks">6 reasons why you should use JavaScript Libraries &#038; Frameworks</a>.</p>
<p>You can download my example source code if it helps you understand how the whole thing works.</p>
<p>Download: <a onclick="_gaq.push(['_trackPageview','/downloads/jquery_example.zip']);" href="http://www.askaboutphp.com/wp-post-images/213/jquery_example.zip"><img src="http://www.askaboutphp.com/wp-post-images/213/jquery_example.png" border="0" alt="download icon" align="middle" /></a></p>
<p>And here&#8217;s a demo of what we&#8217;re trying to do.<br />
<iframe src="http://www.askaboutphp.com/examples/jquery_form/form.php" width="500" height="120"></iframe></p>
<p><b>The traditional way of doing form submissions</b><br />
Back in the &#8220;old&#8221; days, in order to perform a form submission, you need to do something like this.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/213/jquery-php-form1.png"></p>
<p>When you click the &#8220;Submit&#8221; button on <code>form.php</code>, the web server knows to send the name and email values using the POST method to the php script called <code>process.php</code>. The web server will load <code>process.php</code> page and the PHP script will start to read in the form values posted from <code>form.php</code>, maybe perform some validation to check that the information received is correct, then perhaps do something with the form values such as storing it in a database or sending it via email and output a &#8220;thank you&#8221; message.</p>
<p>What if something goes wrong, for example, the person submitting the form wrote in a badly-formed email address, the validation at <code>process.php</code> will throw a nicely worded error message and stop running the rest of the script. The person then would need to go back to the form to correct the email address and he would submit the form again.</p>
<p>This might have been an OK way of doing things 10 years ago, but in this era of Facebook and Twitter, that&#8217;s a pretty antiquated and tedious method.</p>
<p><b>The jQuery way of doing form submissions</b><br />
Here&#8217;s the jQuery way, which is made possible by something called AJAX (which stands for <a href="http://webdesign.about.com/od/ajax/a/aa101705.htm">Asynchronous JavaScript and XML</a>). AJAX is bascially the technology that makes it possible to exchange data with a server, and update parts of a web page &#8211; without reloading the whole page. jQuery includes the necessary functions to implement AJAX into your web application.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/213/jquery-php-form2.png"></p>
<p>The diagram looks quite similar to the &#8220;old&#8221; way of doing things, except that <code>process.php</code> is now represented by a &#8216;circle&#8217;. This is because process.php is now hidden for lack of a better word. In the traditional method, when you click the submit, your browser will load <code>process.php</code> and it will jump from <code>form.php</code> to <code>process.php</code>. </p>
<p>With the jQuery/AJAX way, <code>process.php</code> becomes a background process which the web server will call on, and when you click on the &#8220;Submit&#8221; button, <code>form.php</code> pushes the data to <code>process.php</code>, but your browser will remain showing <code>form.php</code>. Once the <code>process.php</code> has done what it needs to, it will return to <code>form.php</code> some output to be displayed.</p>
<p>Here&#8217;s the source code for <code>form.php</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; 
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;JQuery Form Example&lt;/title&gt; 
	&lt;script type=&quot;text/javascript&quot; src=&quot;http://code.jquery.com/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	$(document).ready(function(){
		$(&quot;#myform&quot;).validate({
			debug: false,
			rules: {
				name: &quot;required&quot;,
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				name: &quot;Please let us know who you are.&quot;,
				email: &quot;A valid email will help us get in touch with you.&quot;,
			},
			submitHandler: function(form) {
				// do other stuff for a valid form
				$.post('process.php', $(&quot;#myform&quot;).serialize(), function(data) {
					$('#results').html(data);
				});
			}
		});
	});
	&lt;/script&gt;
	&lt;style&gt;
	label.error { width: 250px; display: inline; color: red;}
	&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form name=&quot;myform&quot; id=&quot;myform&quot; action=&quot;&quot; method=&quot;POST&quot;&gt;  
&lt;!-- The Name form field --&gt;
    &lt;label for=&quot;name&quot; id=&quot;name_label&quot;&gt;Name&lt;/label&gt;  
    &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; size=&quot;30&quot; value=&quot;&quot;/&gt;  
	&lt;br&gt;
&lt;!-- The Email form field --&gt;
    &lt;label for=&quot;email&quot; id=&quot;email_label&quot;&gt;Email&lt;/label&gt;  
    &lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; size=&quot;30&quot; value=&quot;&quot;/&gt; 
	&lt;br&gt;
&lt;!-- The Submit button --&gt;
	&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;&gt; 
&lt;/form&gt;
&lt;!-- We will output the results from process.php here --&gt;
&lt;div id=&quot;results&quot;&gt;&lt;div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>and the source code for <code>process.php</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Form submitted successfully: &lt;br&gt;Your name is &lt;b&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/b&gt; and your email is &lt;b&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/b&gt;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><b>Here&#8217;s what&#8217;s happening</b><br />
I included jQuery&#8217;s form validation because it provides a more real world example. Usually, most sites will perform processes like form validation at the client-side before the form is submitted. It&#8217;s just more intuitive and a much better user experience. In fact if you can offload as much workload as you can to the browser, it will greatly reduce the hit on your server.</p>
<p>So here&#8217;s a quick high-level walk through what&#8217;s happening on the jQuery part. </p>
<p><img src="http://www.askaboutphp.com/wp-post-images/213/jquery-php-source1.png"></p>
<p>I call the validate method (make sure you have included the jquery validate plugin &#8211; see <code>form.php</code> Line 6) on my form #myform, and proceed to define what to validate. In this case, we&#8217;re checking that the name field is &#8216;required&#8217;, and we&#8217;re checking the email field is not only &#8216;required&#8217;, but must be an email format. I also define the custom error message I want to display if the validation fails.</p>
<p>Lastly, the submitHandler is what gets processed if the validation is successful. In this case, I&#8217;m doing an ajax post method, sending my form data to process.php, and get back any results as HTML data which will be displayed into #results.</p>
<p>Over at <code>process.php</code>, I&#8217;m simply printing out the data received to show you the information was sent and returned.</p>
<p>That&#8217;s basically it. If you want to know more, do check out the <a href="http://jquery.com/">jQuery</a> website to get more details on how to do <a href="http://api.jquery.com/category/ajax/">AJAX</a> and <a href="http://docs.jquery.com/Plugins/Validation">Validation</a>.</p>
<p>Feel free to comment your thoughts or suggestions.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/xPprx-wmkX__opWUF_5b1_RanBk/0/da"><img src="http://feedads.g.doubleclick.net/~a/xPprx-wmkX__opWUF_5b1_RanBk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/xPprx-wmkX__opWUF_5b1_RanBk/1/da"><img src="http://feedads.g.doubleclick.net/~a/xPprx-wmkX__opWUF_5b1_RanBk/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=19vZc1IEN2A:sQun9CgeGlI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=19vZc1IEN2A:sQun9CgeGlI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=19vZc1IEN2A:sQun9CgeGlI:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=19vZc1IEN2A:sQun9CgeGlI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=19vZc1IEN2A:sQun9CgeGlI:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=19vZc1IEN2A:sQun9CgeGlI:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=19vZc1IEN2A:sQun9CgeGlI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=19vZc1IEN2A:sQun9CgeGlI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=19vZc1IEN2A:sQun9CgeGlI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=19vZc1IEN2A:sQun9CgeGlI:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/19vZc1IEN2A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/213/php-and-jquery-submit-a-form-without-refreshing-the-page.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/213/php-and-jquery-submit-a-form-without-refreshing-the-page.html</feedburner:origLink></item>
		<item>
		<title>Google Analytics officially uses the Asynchronous Tracking tag</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/aG6CB2KunzU/google-analytics-officially-uses-the-asynchronous-tracking-tag.html</link>
		<comments>http://www.askaboutphp.com/204/google-analytics-officially-uses-the-asynchronous-tracking-tag.html#comments</comments>
		<pubDate>Thu, 20 May 2010 09:31:58 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[tagging]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=204</guid>
		<description><![CDATA[Google Analytics tagging is now officially changed to the what Google calls Asynchronous Tracking, which came out of beta last week. The new tracking tag is the default and recommended code to use, and shows up in your Google Analytics&#8217; admin interface. 

So what&#8217;s the big deal about this?
Sometime back in December 2009, Google released [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/204/google-analytics-officially-uses-the-asynchronous-tracking-tag.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p>Google Analytics tagging is now <a href="http://analytics.blogspot.com/2010/05/its-now-easy-to-set-up-new-sites-with.html">officially changed to the what Google calls Asynchronous Tracking</a>, which came out of beta last week. The new tracking tag is the default and recommended code to use, and shows up in your Google Analytics&#8217; admin interface. </p>
<p><span id="more-204"></span><br />
<b>So what&#8217;s the big deal about this?</b><br />
Sometime back in December 2009, <a href="http://analytics.blogspot.com/2009/12/google-analytics-launches-asynchronous.html">Google released the Asynchronous Tracking</a> code snippet as an alternative method to tag website to collect website statistics. The new tracking offers some benefits over the previous tracking tags, but the most important one is speed.</p>
<p>Google obviously knows that their previous tracking code slowed things down, since it downloads a fairly large Javascript library file, and while it&#8217;s downloading, nothing else can happen on the page. This is the reason why Google recommends you put the code at the bottom of your webpage.</p>
<p>In most cases, this is not a problem, but you can&#8217;t start tracking until the whole javascript has been loaded, and the user might have navigated away before this happens  (rarely, but it does happen). Also, it does become a headache if we want to track things that happens before the bottom of the page gets loaded, e.g. a call to fire an event and so on.</p>
<p>With the new Asynchronous Tracking, your browser will continue to render the page while the GA javascript loads in the background. Any tracking calls it encounters before the full file has been loaded is pushed into a queue, and executed once the complete javascript file has been loaded.</p>
<p><b>How to start using Asynchronous Tracking tag</b><br />
If you&#8217;ve installed the previous tagging, there&#8217;s nothing new to changing over to the Asynchronous Tracking code. Just go into your Google Analytics admin interface and grab the new code and replace your old code with it.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/204/async-snippet-example.jpg" alt="Google Analytics admin" /></p>
<p>Of course, if you don&#8217;t use the plain vanilla code snippet and have added various other API calls, you need to refer to the <a href="http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html">documentation at Google</a> on the equivalent syntax. Google has some good <a href="http://code.google.com/apis/analytics/docs/tracking/asyncMigrationExamples.html">migration examples</a> to get your started.</p>
<p><b>Should I make the switch?</b><br />
The folks over at Position2 did a pretty good experiment to <a href="http://blogs.position2.com/google-analytics-asynchronous-code-helps-website-tracking-improves-page-load-time">study the effect of using the asynchronous code</a> vs the old code on page load time. So was Google right to claim that the new code speeds things up? </p>
<p>Well, they found that the new code will speed up the page load time if you&#8217;ve been putting your code at the top of the page. But if you&#8217;ve been putting your code snippet at the bottom of the page, there&#8217;s no discernable difference. In fact, the new code clocks a consistent timing no matter where you place it. It was the old code that would slow the page down if it was placed at the top of the page.</p>
<p>It may also be of interest to know that there&#8217;s been quite a bit of chatter in the Google Analytics forum about <a href="http://www.google.com/support/forum/p/Google+Analytics/thread?tid=6e342007520da09c&#038;hl=en">drops in traffic</a> after switching to the new code, and <a href="http://www.google.com/support/forum/p/Google+Analytics/label?lid=5a6c689030bdafe7&#038;hl=en">various other issues</a>. </p>
<p>So, like all things tech, do you want to be the 1st generation of people to use something &#8216;new&#8217;? This entirely boils down to your need. Is your analytics number the lifeblood of your business? Is your site slowed down by heavy GA usage? </p>
<p>Since Google has officially recommended everyone to switch to the new asynchronous tracking code, it&#8217;s just a matter of time before the old code snippet is phased out. You should switch if the benefits of the new code solves your problems or makes tracking easier for you, but otherwise, wait it out a little bit while Google irons out the kinks in the system.</p>
<p>FYI: I have switched to the new tracking code for testing. Let&#8217;s see how it affects my numbers on this site.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/TySyTReZKUl5cDKq6N3ehEH9sw4/0/da"><img src="http://feedads.g.doubleclick.net/~a/TySyTReZKUl5cDKq6N3ehEH9sw4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/TySyTReZKUl5cDKq6N3ehEH9sw4/1/da"><img src="http://feedads.g.doubleclick.net/~a/TySyTReZKUl5cDKq6N3ehEH9sw4/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=aG6CB2KunzU:--qAI8R_Mpo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=aG6CB2KunzU:--qAI8R_Mpo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=aG6CB2KunzU:--qAI8R_Mpo:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=aG6CB2KunzU:--qAI8R_Mpo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=aG6CB2KunzU:--qAI8R_Mpo:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=aG6CB2KunzU:--qAI8R_Mpo:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=aG6CB2KunzU:--qAI8R_Mpo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=aG6CB2KunzU:--qAI8R_Mpo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=aG6CB2KunzU:--qAI8R_Mpo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=aG6CB2KunzU:--qAI8R_Mpo:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/aG6CB2KunzU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/204/google-analytics-officially-uses-the-asynchronous-tracking-tag.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/204/google-analytics-officially-uses-the-asynchronous-tracking-tag.html</feedburner:origLink></item>
		<item>
		<title>PHP Basics: Sorting Arrays</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/HHQIR5-EPCk/php-basics-sorting-arrays.html</link>
		<comments>http://www.askaboutphp.com/191/php-basics-sorting-arrays.html#comments</comments>
		<pubDate>Sun, 14 Mar 2010 14:56:44 +0000</pubDate>
		<dc:creator>Eldee</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=191</guid>
		<description><![CDATA[Arrays are wonderful things. I can&#8217;t imagine using a programming language that does not have support for arrays. For newbies, arrays might be something that&#8217;s difficult to understand at first, but once you get used to it, it&#8217;s almost impossible to live without. Guaranteed!
If you are not familiar with what arrays are, visit the PHP [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/191/php-basics-sorting-arrays.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p><img src="http://www.askaboutphp.com/wp-post-images/191/sorting-arrays.jpg" align="right">Arrays are wonderful things. I can&#8217;t imagine using a programming language that does not have support for arrays. For newbies, arrays might be something that&#8217;s difficult to understand at first, but once you get used to it, it&#8217;s almost impossible to live without. Guaranteed!</p>
<p>If you are not familiar with what arrays are, visit the <a href="http://php.net/manual/en/language.types.array.php">PHP manual</a>. Alternatively, there&#8217;s a <a href="http://www.developer.com/lang/php/article.php/977371/Arrays-in-PHP.htm">introduction to arrays</a> at developer.com.</p>
<p>In this post, I&#8217;m not going to cover the same ground but instead touch on sorting of arrays.</p>
<p><span id="more-191"></span><br />
PHP provides a number of function which you can use to <a href="http://sg2.php.net/manual/en/array.sorting.php">sort arrays</a>. </p>
<p><b>Sorting by its values</b><br />
Sorting an array by its values is probably the most common way of performing a sort, and the most straighfoward. PHP provides the <code>sort()</code> function for doing this.</p>
<p>Example 1:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$nums</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">14</span><span style="color: #339933;">,</span> <span style="color:#800080;">3.2</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color:#800080;">1.3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nums</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nums</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Outputs:
Array 
(
    [0] =&gt; -5
    [1] =&gt; 0
    [2] =&gt; 1.3
    [3] =&gt; 3.2
    [4] =&gt; 14
)
*/</span></pre></td></tr></table></div>

<p>Example 2:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$movies</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A Fish Called Wanda'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The Godfather'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Finding Nemo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Star Wars'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Grease'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Outputs:
Array
(
    [0] =&gt; A Fish Called Wanda
    [1] =&gt; Finding Nemo
    [2] =&gt; Grease
    [3] =&gt; Star Wars
    [4] =&gt; The Godfather
)
*/</span></pre></td></tr></table></div>

<p>Example 3:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$movies</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comedy'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'A Fish Called Wanda'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Drama'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Godfather'</span><span style="color: #339933;">,</span> 
		<span style="color: #0000ff;">'Animation'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Finding Nemo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Sci-Fi'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Star Wars'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Musical'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Grease'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Outputs:
Array
(
    [0] =&gt; A Fish Called Wanda
    [1] =&gt; Finding Nemo
    [2] =&gt; Grease
    [3] =&gt; Star Wars
    [4] =&gt; The Godfather
)
*/</span></pre></td></tr></table></div>

<p>So, it all looks pretty straightfoward right? The arrays are sorted in ascending order. But what has happened to the keys for the last example for $movies? <code>sort()</code> will reset all the indexes, so you have lost your original keys. To get around this you  can use the <code>asort()</code> function instead, which works the same as sort except that it preserves the original key/value mapping.</p>
<p>Example 4:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$movies</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comedy'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'A Fish Called Wanda'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Drama'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Godfather'</span><span style="color: #339933;">,</span> 
		<span style="color: #0000ff;">'Animation'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Finding Nemo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Sci-Fi'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Star Wars'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Musical'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Grease'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">asort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Outputs:
Array
(
    [Comedy] =&gt; A Fish Called Wanda
    [Animation] =&gt; Finding Nemo
    [Musical] =&gt; Grease
    [Sci-Fi] =&gt; Star Wars
    [Drama] =&gt; The Godfather
)
*/</span></pre></td></tr></table></div>

<p>So how about sorting in descending order? Well, the functions to in this case are <code>rsort()</code> and <code>arsort()</code></p>
<p>Example 5:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$movies</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comedy'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'A Fish Called Wanda'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Drama'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Godfather'</span><span style="color: #339933;">,</span> 
		<span style="color: #0000ff;">'Animation'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Finding Nemo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Sci-Fi'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Star Wars'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Musical'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Grease'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">arsort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Outputs:
Array
(
    [Drama] =&gt; The Godfather
    [Sci-Fi] =&gt; Star Wars
    [Musical] =&gt; Grease
    [Animation] =&gt; Finding Nemo
    [Comedy] =&gt; A Fish Called Wanda
)
*/</span></pre></td></tr></table></div>

<p><b>Sorting by its keys</b><br />
For associative arrays, it is just as important to be able to sort the array by its keys. The <code>ksort()</code> and <code>krsort()</code> functions does exactly that.</p>
<p>Example 6:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$movies</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comedy'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'A Fish Called Wanda'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Drama'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Godfather'</span><span style="color: #339933;">,</span> 
		<span style="color: #0000ff;">'Animation'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Finding Nemo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Sci-Fi'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Star Wars'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Musical'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Grease'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ksort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Outputs:
Array
(
    [Animation] =&gt; Finding Nemo
    [Comedy] =&gt; A Fish Called Wanda
    [Drama] =&gt; The Godfather
    [Musical] =&gt; Grease
    [Sci-Fi] =&gt; Star Wars
)
*/</span></pre></td></tr></table></div>

<p>Example 7:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$movies</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comedy'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'A Fish Called Wanda'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Drama'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Godfather'</span><span style="color: #339933;">,</span> 
		<span style="color: #0000ff;">'Animation'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Finding Nemo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Sci-Fi'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Star Wars'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Musical'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Grease'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">krsort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$movies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Outputs:
Array
(
    [Sci-Fi] =&gt; Star Wars
    [Musical] =&gt; Grease
    [Drama] =&gt; The Godfather
    [Comedy] =&gt; A Fish Called Wanda
    [Animation] =&gt; Finding Nemo
)
*/</span></pre></td></tr></table></div>

<p><b>Sorting using custom comparison functions</b><br />
It is also possible to create your own sort criteria and apply it to an array. Three functions are provided for you to do just that &#8211; <code>usort()</code>, <code>uasort()</code> and <code>uksort()</code>. The following example, I&#8217;m going to sort my fruits array by arranging the quantity with odd numbers first followed by even numbers, in descending order. I&#8217;m going to use uasort() because more often than not, you want to preserve your keys, which <code>usort()</code> will not do.</p>
<p>Example 8:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> oddfirst<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #000088;">$j</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># default return value (do nothing)
</span>	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$value</span><span style="color: #339933;">--;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$value</span><span style="color: #339933;">++;</span>	
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$fruits</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'apples'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">37</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mangoes'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">72</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'oranges'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">92</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bananas'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'grapes'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">52</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'kiwis'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">43</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">uasort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fruits</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'oddfirst'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fruits</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Outputs:
Array
(
    [bananas] =&gt; 15
    [apples] =&gt; 37
    [kiwis] =&gt; 43
    [grapes] =&gt; 52
    [mangoes] =&gt; 72
    [oranges] =&gt; 92
)
*/</span></pre></td></tr></table></div>

<p>So how does this actually works? The <code>uasort()</code> function takes in 2 arguments &#8211; the first argument defines the array to be sorted, the second argument states the name of the function to call. In my example, that would be &#8216;oddfirst&#8217;.</p>
<p>This comparison function needs to take in 2 parameters (in my case $i and $j) and return one of three possible values &#8211; a negative number, a positive number and zero. In most cases, returning -1, 0, 1, would be sufficient. This number tells <code>uasort()</code> how $i compares with $j as follows.</p>
<ul>
<li>If a negative number (-1) is returned, then $i is less than $j</li>
<li>If a positive number (1) is returned, then $i is greater than $j</li>
<li>If zero (0) is returned, then $i is equal to $j</li>
</ul>
<p>For the oddfirst() function, my algorithm goes like this:</p>
<ul>
<li>If $i is odd, $j is even then return a negative number ($value=-1) because I want $i to be sorted first</li>
<li>If $i is even, $j is odd then return a positive number ($value=1) because I want $j to be sorted first</li>
<li>if both $i and $j are even or both are odd, then $value is zero, and I need to make a further comparison to sort the numbers in ascending order. Hence, $j < $i tests which number is greater and return $value=1 when $i is greater than $j.</li>
</ul>
<p><b>Sorting multi-dimensional arrays</b><br />
So far, we&#8217;ve only dealt with single dimensional arrays. What about multi-dimensional arrays? PHP provides only one function to this multiple array sorting &#8211; <code>array_multisort()</code>. The function takes in a number of arrays as arguments, each followed optionally by one or more sort flags. Let&#8217;s take a look at the following example of movies with genre and global box office revenue, and attempt to sort the movies by revenue.</p>
<p>Example 9:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$moviedata</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'movie'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Home Alone'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'genre'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Comedy'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'revenue'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">285</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'movie'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Godfather'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'genre'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Drama'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'revenue'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">268</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'movie'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Finding Nemo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'genre'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Animation'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'revenue'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">866</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'movie'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Star Wars'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'genre'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Sci-Fi'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'revenue'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">797</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'movie'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Grease'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'genre'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Musical'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'revenue'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">387</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'movie'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Ghostbusters'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'genre'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Comedy'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'revenue'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">238</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'movie'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Titanic'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'genre'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Drama'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'revenue'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">600</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$cols</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$moviedata</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cols</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$cols</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$cols</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cols</span><span style="color: #339933;">;</span>
<span style="color: #990000;">array_multisort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revenue'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'movie'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'genre'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Outputs:
Array
(
    [movie] =&gt; Array
        (
            [0] =&gt; Ghostbusters
            [1] =&gt; The Godfather
            [2] =&gt; Home Alone
            [3] =&gt; Grease
            [4] =&gt; Titanic
            [5] =&gt; Star Wars
            [6] =&gt; Finding Nemo
        )
&nbsp;
    [genre] =&gt; Array
        (
            [0] =&gt; Comedy
            [1] =&gt; Drama
            [2] =&gt; Comedy
            [3] =&gt; Musical
            [4] =&gt; Drama
            [5] =&gt; Sci-Fi
            [6] =&gt; Animation
        )
&nbsp;
    [revenue] =&gt; Array
        (
            [0] =&gt; 238
            [1] =&gt; 268
            [2] =&gt; 285
            [3] =&gt; 387
            [4] =&gt; 600
            [5] =&gt; 797
            [6] =&gt; 866
        )
&nbsp;
)
*/</span></pre></td></tr></table></div>

<p>To be effective, <code>array_multisort()</code> requires that multidimensional arrays be arranged in a columnar fashion, which is done by the foreach block at line 12 in the example. After that, just call <code>array_multisort()</code> to sort the movie data, I define which columns I want to sort first followed by the next and so on. </p>
<p>You may notice that revenue is sorted in ascending order. If you want sort by descending order, just call <code>array_multisort()</code> with sort flags like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">array_multisort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revenue'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> SORT_DESC<span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'movie'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'genre'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Well, that&#8217;s it. I hope this post helps you get started with how to sort arrays. Remember to check out PHP&#8217;s page on <a href="http://sg2.php.net/manual/en/array.sorting.php">sorting arrays</a>. Feel free to comment and contribute your tips on sorting arrays.</p>
<p>QGYMRRM2NK7K</p>

<p><a href="http://feedads.g.doubleclick.net/~a/MLmqsIIzV60yx8msHqJPhRlVqkI/0/da"><img src="http://feedads.g.doubleclick.net/~a/MLmqsIIzV60yx8msHqJPhRlVqkI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/MLmqsIIzV60yx8msHqJPhRlVqkI/1/da"><img src="http://feedads.g.doubleclick.net/~a/MLmqsIIzV60yx8msHqJPhRlVqkI/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=HHQIR5-EPCk:S2XrMRrv7sg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=HHQIR5-EPCk:S2XrMRrv7sg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=HHQIR5-EPCk:S2XrMRrv7sg:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=HHQIR5-EPCk:S2XrMRrv7sg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=HHQIR5-EPCk:S2XrMRrv7sg:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=HHQIR5-EPCk:S2XrMRrv7sg:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=HHQIR5-EPCk:S2XrMRrv7sg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=HHQIR5-EPCk:S2XrMRrv7sg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=HHQIR5-EPCk:S2XrMRrv7sg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=HHQIR5-EPCk:S2XrMRrv7sg:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/HHQIR5-EPCk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/191/php-basics-sorting-arrays.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/191/php-basics-sorting-arrays.html</feedburner:origLink></item>
		<item>
		<title>Google Analytics Master Class is back in Singapore!</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/zr3gHn1aWGc/google-analytics-master-class-is-back-in-singapore.html</link>
		<comments>http://www.askaboutphp.com/182/google-analytics-master-class-is-back-in-singapore.html#comments</comments>
		<pubDate>Mon, 01 Mar 2010 03:01:04 +0000</pubDate>
		<dc:creator>Eldee</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[google analytics]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=182</guid>
		<description><![CDATA[Last year, I attended the first ever Google Analytics Master Class held here in Singapore. I had a great time. It was a half day packed with excellent presentations for both existing GA users and new people looking to adopt GA.
Well, come March 9, 2010, its back in Singapore! Not only that, folks in Kuala [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/182/google-analytics-master-class-is-back-in-singapore.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p>Last year, I attended the first ever Google Analytics Master Class held here in Singapore. I had a great time. It was a half day packed with excellent presentations for both existing GA users and new people looking to adopt GA.</p>
<p>Well, come March 9, 2010, its back in Singapore! Not only that, folks in Kuala Lumpur, Malaysia will also get their own Google Analytics Master Class on March 11, 2010</p>
<p><span id="more-182"></span><br />
This class is run by the  Google Analytics and Website Optimizer team in Southeast Asia which is headed by the <a href="http://www.blogger.com/profile/03079020355288039199" target="_blank">Vinoaj Vijeyakumaar</a>, Customer Solutions Engineer, Google Southeast Asia. </p>
<p>Last year, they organized a <a href="http://cse-sea.blogspot.com/2009/04/taking-action-with-your-google.html" target="_blank">great set of speakers from Google US and users of Google Analytics</a>. Looking at the list of presentations this year, the one about mobile analytics should be an excellent topic. Getting analytics on mobile users is going to be the big thing in the coming years as more people consume websites and web services via handheld devices.</p>
<p>Another area I&#8217;m looking forward to hearing is Google Website Optimiser. I think this is a great tool for any webmaster to have in their arsenal. The presentations &#8220;Better Landing Pages with Google Website Optimiser&#8221; and &#8220;Price Testing with GWO &#8211; The Holy Grail of Marketing&#8221; should be interesting.</p>
<p>To find out more about this event, read <a href="http://cse-sea.blogspot.com/2010/02/google-analytics-master-class-is-back.html" target="_blank">Google Analytics Master Class is back in Singapore! And also visiting Kuala Lumpur this year!</a> and sign up here for the <a href="https://sites.google.com/site/analyticsmasterclass/singapore" target="_blank">Singapore Master Class</a>.</p>
<p>Last tip for those of you attending for the first time, get there early or you&#8217;re going end up standing through the whole session.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/JOoLjvx_yM4K9S22sK1xcTllExs/0/da"><img src="http://feedads.g.doubleclick.net/~a/JOoLjvx_yM4K9S22sK1xcTllExs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/JOoLjvx_yM4K9S22sK1xcTllExs/1/da"><img src="http://feedads.g.doubleclick.net/~a/JOoLjvx_yM4K9S22sK1xcTllExs/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=zr3gHn1aWGc:6ri3xhaLcNE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=zr3gHn1aWGc:6ri3xhaLcNE:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=zr3gHn1aWGc:6ri3xhaLcNE:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=zr3gHn1aWGc:6ri3xhaLcNE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=zr3gHn1aWGc:6ri3xhaLcNE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=zr3gHn1aWGc:6ri3xhaLcNE:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=zr3gHn1aWGc:6ri3xhaLcNE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=zr3gHn1aWGc:6ri3xhaLcNE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=zr3gHn1aWGc:6ri3xhaLcNE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=zr3gHn1aWGc:6ri3xhaLcNE:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/zr3gHn1aWGc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/182/google-analytics-master-class-is-back-in-singapore.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/182/google-analytics-master-class-is-back-in-singapore.html</feedburner:origLink></item>
		<item>
		<title>Codeigniter: Handling errors</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/8JWJtKK1Fa8/codeigniter-handling-errors.html</link>
		<comments>http://www.askaboutphp.com/172/codeigniter-handling-errors.html#comments</comments>
		<pubDate>Tue, 09 Feb 2010 04:19:53 +0000</pubDate>
		<dc:creator>Eldee</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[errors]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=172</guid>
		<description><![CDATA[As coders, I&#8217;m sure we all know the value of good error handling. So I thought a quick post about how Codeigniter deals with those pesky errors would be a good post. 
The way I see it, there are 2 types of errors we have to work with. The ones which are displayed out in [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/172/codeigniter-handling-errors.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p>As coders, I&#8217;m sure we all know the value of good error handling. So I thought a quick post about how Codeigniter deals with those pesky errors would be a good post. </p>
<p>The way I see it, there are 2 types of errors we have to work with. The ones which are displayed out in nice friendly text to your users, and the type which are hidden and shown only to you as the coder to figure out where something has gone wrong. CI provides the means to do both, thankfully.</p>
<p><span id="more-172"></span></p>
<p><strong>System/Application Errors</strong><br />
Let&#8217;s start with having a look at how CI deals with PHP errors. By default, on a clean install, CI will display ALL php errors of all severity. So if you make a mistake in your PHP coding, you&#8217;ll see plenty of these&#8230;</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/172/ci-error-1.png"></p>
<p>CI uses PHP&#8217;s <code>error_reporting()</code> function to define the level of error reporting, and you can find this in the main <code>index.php</code> file in the root of your CI install. It&#8217;s the first function you see.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/172/ci-error-2.png"></p>
<p>Instead of E_ALL, you can change it to any of the <a href="http://sg2.php.net/manual/en/errorfunc.constants.php">predefined error constant</a> that PHP understands to suit your needs. Obviously, once your site goes live, you should change from E_ALL to E_ERROR to show only messages for fatal run time problems. This will hide all php errors except those that will halt your script execution.</p>
<p>So, if the error messages are hidden, how else can we tell if something is not working right? Well, CI can writes out any errors it encounters into its log file. You can configure your CI log file by going to the <code>config.php</code> file in your <code>applications/config</code> directory. </p>
<p><img src="http://www.askaboutphp.com/wp-post-images/172/ci-error-3.png"></p>
<p>By default, the logs are turned off, so you should turn it on by setting the <code>$config['log_threshold']</code> variable. Once enabled, the logs will appear in the <code>system/logs</code> folder of your CI install. You can set the location of your log file if you wish to keep your logs elsewhere by defining a path for the <code>$config['log_path']</code> variable.</p>
<p>You may notice that the <code>$config['log_threshold']</code> allows a few settings.</p>
<ul>
<li> <strong>1 &#8211; ERROR</strong><br />This will log down all E_ALL level php generated errors, HTML status code errors (like 404s) and any user-defined errors.</li>
<li> <strong>2 &#8211; DEBUG</strong><br />In addition to ERROR messages, this will show messages which helps you to debug your CI application.</li>
<li> <strong>3 &#8211; INFO</strong><br />This level will show all ERROR &#038; DEBUG messages as well as any user-defined informational messages. CI doesn&#8217;t natively generate any INFO messages but you can do so in your application.</li>
<li> <strong>4 &#8211; All Messages</strong><br />This will show all log messages. I could not see any difference between this level and level 3 setting. If you do know a difference, post it into the comments.</li>
</ul>
<p>In addition CI&#8217;s natively generated messages, you can define your own messages by calling the <code>log_message()</code> function. You can call this anywhere in your code, and you can set what level of messaging (error, debug, or info) you want logged. (<a href="http://codeigniter.com/user_guide/general/errors.html" target="_blank">See CI&#8217;s guide on how to use the log_message() function</a>.)</p>
<p><strong>Displaying Errors</strong><br />
Next, let&#8217;s look at what options are available if you want to display error messages to your user. CI provides 2 functions for this purpose &#8211; <code>show_error()</code> and <code>show_404()</code>. (<a href="http://codeigniter.com/user_guide/general/errors.html" target="_blank">See CI&#8217;s guide on how to use the show_error() and show_404() functions</a>.)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>SHOW_ERROR<span style="color: #339933;">==</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	show_error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is where your error message will appear surrounded by this default template.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When you call <code>show_error()</code>, you will generate page that looks like this. The layout can changed by modifying this file <code>application/errors/error_general.php</code>)</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/172/ci-error-5.png"></p>
<p>show_404() works in a similar way, except it will display the <code>application/errors/error_404.php</code> layout and will throw a HTTP status code of 404.</p>
<p>Both of these functions are breakpoints and will stop the execution of your script, so any functions that follows these will not be processed.</p>
<p>That&#8217;s it. Feel free to comment.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/9MjHh9BUtqVZJF-stV6BUdtV-tA/0/da"><img src="http://feedads.g.doubleclick.net/~a/9MjHh9BUtqVZJF-stV6BUdtV-tA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/9MjHh9BUtqVZJF-stV6BUdtV-tA/1/da"><img src="http://feedads.g.doubleclick.net/~a/9MjHh9BUtqVZJF-stV6BUdtV-tA/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=8JWJtKK1Fa8:vXXiJK6Ap2g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=8JWJtKK1Fa8:vXXiJK6Ap2g:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=8JWJtKK1Fa8:vXXiJK6Ap2g:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=8JWJtKK1Fa8:vXXiJK6Ap2g:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=8JWJtKK1Fa8:vXXiJK6Ap2g:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=8JWJtKK1Fa8:vXXiJK6Ap2g:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=8JWJtKK1Fa8:vXXiJK6Ap2g:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=8JWJtKK1Fa8:vXXiJK6Ap2g:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=8JWJtKK1Fa8:vXXiJK6Ap2g:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=8JWJtKK1Fa8:vXXiJK6Ap2g:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/8JWJtKK1Fa8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/172/codeigniter-handling-errors.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/172/codeigniter-handling-errors.html</feedburner:origLink></item>
		<item>
		<title>Pentaho: A beginner’s perspective</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/JjPzLdSwtsk/pentaho-a-beginners-perspective.html</link>
		<comments>http://www.askaboutphp.com/149/pentaho-a-beginners-perspective.html#comments</comments>
		<pubDate>Thu, 07 Jan 2010 09:28:23 +0000</pubDate>
		<dc:creator>Eldee</dc:creator>
				<category><![CDATA[Pentaho]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[data warehouse]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=149</guid>
		<description><![CDATA[For the last 6 months, I&#8217;ve been buried deep in the world of Business Intelligence (or BI for short) and the mind-numbing field that is Data Warehousing and Data Mining. Given that I&#8217;m not really a database person, and I only use MySQL with my PHP development, this was a whole new experience for me. [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/149/pentaho-a-beginners-perspective.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p>For the last 6 months, I&#8217;ve been buried deep in the world of Business Intelligence (or BI for short) and the mind-numbing field that is Data Warehousing and Data Mining. Given that I&#8217;m not really a database person, and I only use MySQL with my PHP development, this was a whole new experience for me. </p>
<p>I&#8217;m writing this post because when I first laid my eyes on Pentaho, I was confused as hell. What I didn&#8217;t know was that Pentaho is not a single product, but a collection of open-source tools that have been meshed together to form a suite for BI. All the documentation and writeup at the website on the different aspects of Pentaho just didn&#8217;t gel together, leading to a very steep learning curve.</p>
<p>Hence, I&#8217;m just going to briefly cover the various aspects that makes up Pentaho, so that if you are just starting to use Pentaho, this would hopefully give you a good overview.</p>
<p><span id="more-149"></span><br />
Pentaho is available in two flavors, a paid commerical version and an open-source community version. Obviously, if you opt for the paid version, you get all the expert help and support so things should be straightforward. But, if you are unfornate enough like myself to be stuck with the community version, you have to try to make sense of everything on your own.</p>
<p>If you visit the Pentaho Community version&#8217;s homepage, you should see there are essentially five projects that makes up the Pentaho Platform.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/149/pentaho-community-home.jpg"></p>
<p>What&#8217;s confusing is that the community version website shows one naming scheme which is slightly different from what folders in SourceForge presents, or the link points you to an older version. All this confusion is really a sign of the work in progress by the Pentaho team to try to integrate the tools into a cohesive suite.</p>
<p>The best representation of Pentaho is to look at how the <a href="http://sourceforge.net/projects/pentaho/files/">files at SourceForge</a> is organized.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/149/pentaho-sourceforge.jpg"></p>
<p><strong>Data Integration (PDI)</strong><br />
In the world of Data Warehousing, there&#8217;s a process called ETL which stands for Extraction, Transformation and Loading. This is really the process of compiling data from various sources, cleaning it up and stuffing it into the Data Warehouse (which is just another database system). </p>
<p>The Pentaho Data Integration (PDI) tool (which is listed as Kettle project at the community version website), primarily contains the Spoon application, that provides a graphical model-driven approach to ETL. You would use it to craft your own ETL using the library of transformation processes.</p>
<p>Here&#8217;s an example of a simple process to load records from one MySQL table into another.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/149/pentaho-di.jpg"></p>
<p>In my case, although I was quite impressed by how the tool works, I still ended up creating my own ETL process using cron and command-line PHP. It was really a time issue that led me to use PHP for the ETL process. I just didn&#8217;t have the time to learn how the 100+ transformation work and master it for the project.</p>
<p><strong>Report Designer (PRD)</strong><br />
The Pentho Report Designer (PRD) is front-end application for building and publishing reports to the Pentaho platform. It publishes in a new file format .prpt which the Pentaho server recognizes and knows how to intepret it to display.</p>
<p>The tool works very much like other WYSIWYG-based reporting tools like Microsoft Access reporting or Crystal Reports. You define your database connection using JDBC/JDNI, and drag reporting elements like text field etc onto the report, and tie them to the corresponding database field.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/149/pentaho-prd1.jpg"></p>
<p><strong>Business Intelligence Server</strong><br />
This is the core of Pentaho. It is made up of 3 parts &#8211; the core platform itself, the BI components and the presentation layer.</p>
<p>The core platform is where all the low-level functions occurs, such as database connection management, solution repository, user authentication, task scheduling, logging etc.</p>
<p>The BI component part is where the various BI engines are plugged into, such as the reporting engine, the OLAP engine, the ETL engine and the Data Mining engine. This is where all the churning of the data occurs and spits it out to presentation layer.</p>
<p>The presentation layer is where the Pentaho users will interact with platform, to view reports, dashboard, perform analysis etc. </p>
<p><img src="http://www.askaboutphp.com/wp-post-images/149/pentaho-reporting-1.jpg"></p>
<p><img src="http://www.askaboutphp.com/wp-post-images/149/pentaho-reporting-2.jpg"></p>
<p><strong>Design Studio</strong><br />
The Pentaho Design Studio (PDS) is essentially an Eclipse IDE with a Pentaho plugin that is used to create and maintain action sequences that work within the Pentaho platform. Action sequences is a predefined set of actions which can be triggered by a user&#8217;s action, a schedule or any other action sequence. Action sequence can be as simple as &#8220;display the report&#8221; to as complex &#8220;find all overdue orders and send out a reminder email&#8221;.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/149/pentaho-design-studio-2.jpg"></p>
<p><strong>Mondrian or Pentaho Analysis Service (PAS)</strong><br />
PAS or Mondrian provides OLAP capabilities to the Pentaho platform. When we talk about BI and Data Warehousing, the most common term you hear is &#8217;slice-and-dice&#8217;, well, this is essentially what OLAP enables you to do within Pentaho. By representing your data in a multi-dimensional cube, you can easily drill-down, drill-up, slice or dice the cube to gain insights.</p>
<p>Once you have defined your cube, you can publish it Pentaho server, and it will be available under the &#8216;New Analysis View&#8217; option.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/149/pentaho-mondrian.jpg"></p>
<p>I know this post doesn&#8217;t cover much in detail and I&#8217;ve skipped a few components like Pentaho Metadata and Weka. What I&#8217;ve listed is really what I&#8217;ve used. Nonetheless, I hope this overview of Pentaho will be useful and helpful to someone at least. Feel free to comment (or correct anything I might have gotten wrong).</p>
<p>Lastly, Pentaho is by no means the only open-source BI tool available, here&#8217;s a <a href="http://en.wikipedia.org/wiki/Business_intelligence_tools">list of other BI tools</a>.</p>
<p>If you would like to get yourself a book, I would recommend <a href="http://www.amazon.com/Pentaho-Solutions-Business-Intelligence-Warehousing/dp/0470484322/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1262855944&#038;sr=8-1" target="_blank">Pentaho Solutions by Roland Bouman and Jos van Dongen</a>. It would get you started in the right direction.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/0s8l4exQ4Zbji6FCZqMvNSi-lTQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/0s8l4exQ4Zbji6FCZqMvNSi-lTQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/0s8l4exQ4Zbji6FCZqMvNSi-lTQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/0s8l4exQ4Zbji6FCZqMvNSi-lTQ/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=JjPzLdSwtsk:IwTN89P4hCY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=JjPzLdSwtsk:IwTN89P4hCY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=JjPzLdSwtsk:IwTN89P4hCY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=JjPzLdSwtsk:IwTN89P4hCY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=JjPzLdSwtsk:IwTN89P4hCY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=JjPzLdSwtsk:IwTN89P4hCY:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=JjPzLdSwtsk:IwTN89P4hCY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=JjPzLdSwtsk:IwTN89P4hCY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=JjPzLdSwtsk:IwTN89P4hCY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=JjPzLdSwtsk:IwTN89P4hCY:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/JjPzLdSwtsk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/149/pentaho-a-beginners-perspective.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/149/pentaho-a-beginners-perspective.html</feedburner:origLink></item>
		<item>
		<title>Site Update: 2 years old!</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/6cRAwo_c_GA/site-update-2-years-old.html</link>
		<comments>http://www.askaboutphp.com/133/site-update-2-years-old.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 03:36:09 +0000</pubDate>
		<dc:creator>Eldee</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[site update]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=133</guid>
		<description><![CDATA[Come December 4th, this site will be 2 years old! How time flies. To mark this occasion, I&#8217;ve revamped the look of the site, and will continue to tweak various things in the days ahead.


Looking back, the site got off on a slow start, as I forgot to turn off the privacy settings in Wordpress [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/133/site-update-2-years-old.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p>Come December 4th, this site will be 2 years old! How time flies. To mark this occasion, I&#8217;ve revamped the look of the site, and will continue to tweak various things in the days ahead.<br />
<span id="more-133"></span></p>
<p><img src="http://www.askaboutphp.com/wp-post-images/133/aap-gatraffic.gif"></p>
<p>Looking back, the site got off on a slow start, as I forgot to <a href="http://www.askaboutphp.com/website-building/18/wordpress-noindex-nofollow-meta-tags-problem.html">turn off the privacy settings in Wordpress</a> and was wondering why there were still no traffic after 3 months. Once that problem was fixed, the Google-love came rushing in!</p>
<p>So far, I&#8217;ve had a real blast running this blog about PHP. Like all things in IT, you can never finish learning, and the same goes for PHP. I&#8217;ve used PHP on and off for my work in the last 10 years, and there are still things about PHP that I have to catch up on, and some old PHP habits to unlearn. Either way, it&#8217;s been a great experience.</p>
<p><strong>5 most visited posts to date</strong><br />
To date, these are my 5 most visited posts. </p>
<ol>
<li><a href="http://www.askaboutphp.com/tutorials/63/google-analytics-api-class-for-php.html">Google Analytics API class for PHP</a></li>
<li><a href="http://www.askaboutphp.com/tutorials/25/regex-extract-content.html">Using regular expressions to extract content</a></li>
<li><a href="http://www.askaboutphp.com/beginners/7/installing-xampp-lite-on-a-portable-storage-device.html">Installing XAMPP Lite on a Portable Storage device</a></li>
<li><a href="http://www.askaboutphp.com/tutorials/22/checking-a-string-is-alphanumeric-in-php.html">Checking a string is alphanumeric in PHP</a></li>
<li><a href="http://www.askaboutphp.com/beginners/48/codeigniter-organizing-views-simply.html">CodeIgniter: Organizing views simply</a></li>
</ol>
<p>I&#8217;m most surprised to see that traffic keeps coming for the post about alphanumeric checking.</p>
<p><strong>Top search engine</strong><br />
Google is the top traffic contributor to this site (no surprise there), but I am getting almost ALL my search traffic from Google, with Yahoo followed by Bing, in the very distant 2nd and 3rd position. Not sure if this a good thing&#8230;.</p>
<p><strong>Top 3 browsers</strong></p>
<ol>
<li>Mozilla Firefox</li>
<li>Internet Explorer</li>
<li>Google Chrome</li>
</ol>
<p>Almost 70% of you guys are using Firefox. Firefox used to be my default browser, but not so anymore. Since version 3.5, I&#8217;ve had problems with Firefox and memory problems. I&#8217;ve switched to Chrome and liking it a lot more. Firefox is still great for the plug-ins I need, but Chrome is now my default browser. Chrome is just blazingly fast.</p>
<p><strong>Coming up&#8230;</strong><br />
Being a technical guy, I&#8217;m not really a good writer, so crafting these posts is a lot of  hard work for me. Nevertheless, I will try to push out at least one post per month. I&#8217;m also planning to branch into topics about <a href="http://www.pentaho.com" target="_blank">Pentaho</a>, since that&#8217;s what I&#8217;m spending most of my work time on these days. I&#8217;m quite sure there are some insights that I&#8217;ve learnt that might be useful for someone out there. </p>
<p><strong>Thank you all!</strong><br />
Lastly, I just want to thank you all for your support and the wonderful comments to my posts. Keep them coming!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/KhlsVeET_PvRWxV8pveGT6LSdAA/0/da"><img src="http://feedads.g.doubleclick.net/~a/KhlsVeET_PvRWxV8pveGT6LSdAA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/KhlsVeET_PvRWxV8pveGT6LSdAA/1/da"><img src="http://feedads.g.doubleclick.net/~a/KhlsVeET_PvRWxV8pveGT6LSdAA/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=6cRAwo_c_GA:mYfAIL9CDM0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=6cRAwo_c_GA:mYfAIL9CDM0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=6cRAwo_c_GA:mYfAIL9CDM0:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=6cRAwo_c_GA:mYfAIL9CDM0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=6cRAwo_c_GA:mYfAIL9CDM0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=6cRAwo_c_GA:mYfAIL9CDM0:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=6cRAwo_c_GA:mYfAIL9CDM0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=6cRAwo_c_GA:mYfAIL9CDM0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=6cRAwo_c_GA:mYfAIL9CDM0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=6cRAwo_c_GA:mYfAIL9CDM0:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/6cRAwo_c_GA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/133/site-update-2-years-old.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/133/site-update-2-years-old.html</feedburner:origLink></item>
		<item>
		<title>Codeigniter: Intergrating OpenFlashCharts</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/xwn1_LW1Vr0/codeigniter-intergrating-openflashcharts.html</link>
		<comments>http://www.askaboutphp.com/113/codeigniter-intergrating-openflashcharts.html#comments</comments>
		<pubDate>Fri, 06 Nov 2009 05:12:34 +0000</pubDate>
		<dc:creator>Eldee</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[openflashcharts]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=113</guid>
		<description><![CDATA[Yes I know, it has been some time since I last posted anything on the site. Things have just been crazy at work, trying to get up to speed on using Pentaho for a major project. In fact, I might start posting some Pentaho related topics in the future. There&#8217;s definitely a need for more [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/113/codeigniter-intergrating-openflashcharts.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p>Yes I know, it has been some time since I last posted anything on the site. Things have just been crazy at work, trying to get up to speed on using <a href="http://community.pentaho.com/" target="_blank">Pentaho</a> for a major project. In fact, I might start posting some Pentaho related topics in the future. There&#8217;s definitely a need for more help and guides on using Pentaho for beginners.</p>
<p>Anyway, one of the things on the project was to pull data from Pentaho and display it inside OpenFlashCharts on a CI platform. If you don&#8217;t know what <a href="http://teethgrinder.co.uk/open-flash-chart-2/" target="_blank">OpenFlashCharts</a> is, go visit the website. It&#8217;s a pretty awesome kit.</p>
<p>There&#8217;s been quite a bit of chatter on the net about integrating CI with OpenFlashCharts, but ever since version 2 came out there have been more questions about how to do it.<br />
<span id="more-113"></span><br />
In the new version of OpenFlashCharts, it uses the JSON format to describe what type of chart to render in the flash object. OFC comes with a bunch of libraries (in various programming languages) which will generate the JSON format for the flash object. For PHP, the kit comes with the generic PHP version and a PHP5 version.</p>
<p>Somebody by the name of Thomas did managed to stitch <a href="http://codeigniter.com/wiki/Open_Flash_Chart_2/" target="_blank">OpenFlashCharts 2 with CI</a> and he posted it up on the CI wiki. So kudos to Thomas (whoever you are) for making my life easier. If you like you can download his library and give it a spin.</p>
<p>For Thomas, he used the PHP5 libraries of OpenFlashCharts, which unfortunately is a bit incomplete. I wasn&#8217;t able to generate more advance graphs such as Hollow Areas, Dotted lines etc. The flash object gave me an &#8216;infinity&#8217; error. After some investigation, I found that the OFC PHP5 libraries are not generating the same JSON as the generic PHP version. Taking a page out of his book, I modified his library to work with the generic PHP version instead. </p>
<p>One advantage of doing this is that suddenly, you can apply all the tutorial codes on the OFC website because they were written for the generic PHP library and not the PHP5 version.</p>
<p>Download: <a onclick="_gaq.push(['_trackPageview','/downloads/ci-ofc2.zip']);" href="http://www.askaboutphp.com/wp-post-images/113/ci-ofc2.zip"><img src="http://www.askaboutphp.com/wp-post-images/113/ci-ofc2-download.gif" border="0" alt="download icon" align="middle" /></a></p>
<p>So, download the zip file and extract the files to the relevant folders of your CI install. The assets folder should go to wherever you put your stuff like images and javascript files. Just make sure you change the view to reflect the correct path. I put my assets in the root of my webserver folder, and I access my CI through <code>http://dev.ci/</code>.</p>
<p>When I run the <code>http://dev.ci/charts</code>, I would get this graph with 3 data lines.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/113/ofc2-test-chart.gif" alt="OFC Test Chart" /></p>
<p><strong>So how does it all work? </strong><br />
The OFC library, <code>php-ofc-library</code> and the <code>OpenFlashChartLib.php</code> can now be accessed by calling the load library call.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OpenFlashChartLib'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'OFCL'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you look inside the view folder for <code>chart_view.php</code>, you can see where the OFC flash object is getting its JSON feed from, <code>http://dev.ci/charts/get_data</code>.</p>
<p>Inside <code>get_data()</code> function of the charts controller, it&#8217;s basically the same code as the tutorial at <a href="http://teethgrinder.co.uk/open-flash-chart-2/data-lines-2.php">http://teethgrinder.co.uk/open-flash-chart-2/data-lines-2.php</a> </p>
<p>The difference here is that instead of calling the</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$chart</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> open_flash_chart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I&#8217;m now doing</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$chart</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">OFCL</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'open_flash_chart'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>to perform the same instantiation but through the OpenFlashChartLib (OFCL) library.</p>
<p>So, just change all the object instantiation call accordingly, and the graph should show up nice and neat.</p>
<p>Here&#8217;s Dilbert to close out&#8230;</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/113/dilbert-pie-chart.png" alt="Dilbert Pie Chart" /></p>

<p><a href="http://feedads.g.doubleclick.net/~a/MPombSAutv0bU4p_UlKI90-At3c/0/da"><img src="http://feedads.g.doubleclick.net/~a/MPombSAutv0bU4p_UlKI90-At3c/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/MPombSAutv0bU4p_UlKI90-At3c/1/da"><img src="http://feedads.g.doubleclick.net/~a/MPombSAutv0bU4p_UlKI90-At3c/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=xwn1_LW1Vr0:ZiSK0NckehY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=xwn1_LW1Vr0:ZiSK0NckehY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=xwn1_LW1Vr0:ZiSK0NckehY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=xwn1_LW1Vr0:ZiSK0NckehY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=xwn1_LW1Vr0:ZiSK0NckehY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=xwn1_LW1Vr0:ZiSK0NckehY:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=xwn1_LW1Vr0:ZiSK0NckehY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=xwn1_LW1Vr0:ZiSK0NckehY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=xwn1_LW1Vr0:ZiSK0NckehY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=xwn1_LW1Vr0:ZiSK0NckehY:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/xwn1_LW1Vr0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/113/codeigniter-intergrating-openflashcharts.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/113/codeigniter-intergrating-openflashcharts.html</feedburner:origLink></item>
		<item>
		<title>Codeigniter: Setting up multiple sites on one install</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/0UHJyC85F2c/codeigniter-setting-up-multiple-sites-on-one-install.html</link>
		<comments>http://www.askaboutphp.com/88/codeigniter-setting-up-multiple-sites-on-one-install.html#comments</comments>
		<pubDate>Wed, 19 Aug 2009 08:19:40 +0000</pubDate>
		<dc:creator>Eldee</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=88</guid>
		<description><![CDATA[It&#8217;s been awhile since I last posted about Codeigniter. In this post, I&#8217;m going to walkthrough how I setup a CI install that can support multiple sites. This is by no means the only way to do it, but it&#8217;s what works for me.
CI&#8217;s default folder structure is really geared towards one site domain, and [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/88/codeigniter-setting-up-multiple-sites-on-one-install.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p>It&#8217;s been awhile since I <a href="http://www.askaboutphp.com/tutorials/58/codeigniter-mixing-segment-based-url-with-querystrings.html">last posted about Codeigniter</a>. In this post, I&#8217;m going to walkthrough how I setup a CI install that can support multiple sites. This is by no means the only way to do it, but it&#8217;s what works for me.</p>
<p>CI&#8217;s default folder structure is really geared towards one site domain, and having both the <code>application</code> folder and the <code>system</code> folder visible to the browser is not exactly a secure approach.</p>
<p>By configuring your install to support multiple sites, not only do you make the updating of the CI core easier, but also make the CI install more secure as a whole. So without delay, let&#8217;s get started&#8230;</p>
<p><span id="more-88"></span></p>
<p>In this walkthrough, I&#8217;m setting up my multiple CI sites on my local XAMPP install, which is on my <code>M:\ drive</code>. Your Apache setup might be different, so do take note of my settings and adjust according to your own web server environment.</p>
<p>I&#8217;m planning to setup two sites just for illustration &#8211; <code>http://dev.ci/</code> and <code>http://live.ci/</code>.</p>
<p><strong>Codeigniter default folder structure</strong><br />
When you first unzip the downloaded CI file, you would get something like this:</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/88/ci-sites-1.jpg"></p>
<p>You would have set your Apache&#8217;s configuration to point to your CI folder (which is <code>M:\xampplite\CodeIgniter_1.7.1</code> for me) as the document root. Once you hit the site in your browser, you would get the standard welcome page.</p>
<p>If you have setup the default CI before, you may know that within the <code>system</code> folder are a bunch of core folders which you don&#8217;t normally need to touch and the <code>application</code> folder which will house all your codes for your site. You may also have noticed the <code>index.php</code> file in the root of the CI directory, which you didn&#8217;t really need to touch before but will become crucial in setting up multiple sites.</p>
<p><strong>Adjusting the application folders</strong><br />
First thing I do is to move the <code>application</code> folder out of the <code>system</code> folder to the same level as the <code>system</code> folder.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/88/ci-sites-2.jpg"></p>
<p>Since I&#8217;m setting up to run two distinct sites sharing the same CI core, I will make another copy of the <code>application</code> folder and rename both folders to reflect the different sites.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/88/ci-sites-3.jpg"></p>
<p><strong>Create the web root folders</strong><br />
Next, we would need two folders which will be the website&#8217;s root folders. This is how I setup mine.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/88/ci-sites-4.jpg"></p>
<p>Make copies of the <code>index.php</code> file located in the CI&#8217;s root folder (ie <code>M:\xampplite\CodeIgniter_1.7.1</code>) into each of the htdocs folder. In this case, I would have one <code>index.php</code> in each of my <code>htdocs_ci_dev</code> and <code>htdocs_ci_live</code> folders.</p>
<p>Open <code>index.php</code> file for each site and edit the following lines.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">At Line 26:
	$system_folder = &quot;system&quot;;
Change to 
	$system_folder = &quot;../system&quot;;
&nbsp;
At Line 43:
	$application_folder = &quot;application&quot;;
Change to 
	$application_folder = &quot;../app_ci_dev&quot;; (for the htdocs_ci_dev)
or 
	$application_folder = &quot;../app_ci_live&quot;; (for the htdocs_ci_live)</pre></div></div>

<p><strong>Configure Apache virtual hosts</strong><br />
Once that&#8217;s done, the last thing to do is to setup the Apache virtual host configuration of my XAMPP install. </p>
<p>My Apache virtual host configuration looks like this:</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/88/ci-sites-5.png"></p>
<p>Don&#8217;t forget to edit your local hosts file so that your system recognizes the dev.ci and live.ci domains. </p>
<p>Once you fire up your Apache web server, you should be able to load either site accordingly (*fingers crossed*)</p>
<p><strong>Renaming the <code>system</code> folder</strong><br />
If you want to go further you can rename the <code>system</code> folder to reflect the different CI versions. This way, when a new version of the CI core is released, you can configure your sites easily by just changing <code>$system_folder</code> parameter in the index.php file (Line 26) for each site.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/88/ci-sites-6.jpg"></p>
<p><strong>Conclusion</strong><br />
I think you will agree that with this setup, you can easily expand the CI install to more sites. There is also no doubt that this is more secure than the default CI setup, as the only folders which are exposed to the browser are the htdocs folders &#8211; all the <code>application</code> and <code>system</code> folders are no longer accessible through the web server. </p>
<p>Of course, this is not the only way you can configure CI for multiple sites/applications, check out some of these alternatives:<br />
- <a href="http://codeigniter.com/wiki/Multiple_Applications/" target="_blank">CodeIgniter Wiki &#8211; Multiple Applications</a><br />
- <a href="http://www.michaelwales.com/codeigniter/secure-application-starting-point" target="_blank">Michael Wales &#8211; CodeIgniter Advent: Day 1</a><br />
- <a href="http://www.codeofficer.com/blog/entry/multiple_codeigniter_sites_using_symlinks/" target="_blank">Multiple codeigniter sites, using symlinks</a></p>
<p>Please feel free to give your thoughts and feedback. Thanks!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/QSpNaheRNbYqkofuVhapYHYesQE/0/da"><img src="http://feedads.g.doubleclick.net/~a/QSpNaheRNbYqkofuVhapYHYesQE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/QSpNaheRNbYqkofuVhapYHYesQE/1/da"><img src="http://feedads.g.doubleclick.net/~a/QSpNaheRNbYqkofuVhapYHYesQE/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=0UHJyC85F2c:tV5brm_7GDM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=0UHJyC85F2c:tV5brm_7GDM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=0UHJyC85F2c:tV5brm_7GDM:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=0UHJyC85F2c:tV5brm_7GDM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=0UHJyC85F2c:tV5brm_7GDM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=0UHJyC85F2c:tV5brm_7GDM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=0UHJyC85F2c:tV5brm_7GDM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=0UHJyC85F2c:tV5brm_7GDM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=0UHJyC85F2c:tV5brm_7GDM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=0UHJyC85F2c:tV5brm_7GDM:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/0UHJyC85F2c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/88/codeigniter-setting-up-multiple-sites-on-one-install.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/88/codeigniter-setting-up-multiple-sites-on-one-install.html</feedburner:origLink></item>
		<item>
		<title>WebPageTest: The little known but great webpage benchmarking tool.</title>
		<link>http://feedproxy.google.com/~r/AskAboutPhp/~3/4cuzzhIe1tE/webpagetest-tool-the-little-known-but-great-webpage-benchmarking-tool.html</link>
		<comments>http://www.askaboutphp.com/71/webpagetest-tool-the-little-known-but-great-webpage-benchmarking-tool.html#comments</comments>
		<pubDate>Fri, 31 Jul 2009 15:43:19 +0000</pubDate>
		<dc:creator>Eldee</dc:creator>
				<category><![CDATA[Website Building/SEO]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[webpagetest]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.askaboutphp.com/?p=71</guid>
		<description><![CDATA[When it comes to testing how fast a webpage loads, many of us are familiar with Firebug/Yslow tool (installable as a Firefox browser plug-in). Firebug/Yslow is a fantastic plug-in for Firefox, it gives a wealth of information about any webpage as your browser renders it. This is a must have for any webmaster&#8217;s toolbox. Unfortunately, [...]]]></description>
			<content:encoded><![CDATA[<fb:like 
		href="http://www.askaboutphp.com/71/webpagetest-tool-the-little-known-but-great-webpage-benchmarking-tool.html" 
		layout="standard" 
		show_faces="false" 
		width="450" 
		height="30"
		action="like" 
		colorscheme="light" 
		style="margin-left:10px;margin-bottom:5px;"
		class="fb_edge_widget_with_comment fb_iframe_widget"></fb:like><p>When it comes to testing how fast a webpage loads, many of us are familiar with <a href="http://developer.yahoo.com/yslow/" target="_blank">Firebug/Yslow</a> tool (installable as a Firefox browser plug-in). Firebug/Yslow is a fantastic plug-in for Firefox, it gives a wealth of information about any webpage as your browser renders it. This is a must have for any webmaster&#8217;s toolbox. Unfortunately, using Firebug/Yslow is very ad-hoc, which is great for troubleshooting, but tedious when you want to export data or take more than 1 snapshot.</p>
<p>After some searching I came across another tool &#8211; <a href="http://www.webpagetest.org/" target="_blank">webpagetest.org</a>. This site tests your url and presents its findings and recommendations on optimizating your webpage, with some nice Firebug/Yslow-like waterfall diagram and charts. Check out the <a href="http://www.webpagetest.org/result/090731_204R/" target="_blank">results for this site as tested </a>from Dulles, Virginia in the US. Good stuff right?</p>
<p><span id="more-71"></span><br />
What&#8217;s really great about this is that Pat Meenan, the man behind this tool, has generously made available for <a href="http://sourceforge.net/projects/pagetest/files/" target="_blank">download a desktop/browser version and a hosted version</a>. The desktop version is not much different from the Firebug/Yslow tool, but the hosted version is what I found most useful and will cover in this article.</p>
<p>With the hosted version, I can setup my own webpagetest.org site within my organisation&#8217;s network and open it up to my co-workers to use. Any test results can be shared by easily posting a link, or browsed from the Test History tab. The package itself contains the website which is written in PHP and a tester program. With the PHP source code, I can easily shape the tool to our requirements.</p>
<p><strong>Setting up your own hosted WebPageTest</strong><br />
If you haven&#8217;t already done so, go download a copy. With it, you can choose to deploy it in a single machine configuration or you can opt to split the website away from the tester. This will allow you to setup a one website with multiple testers configuration.</p>
<p>The tester program requires the IE browser, hence will only work on a Windows platform. It tests by firing up the browser and recording the data as the page renders. The website however, being PHP can function within either Linux or Windows platform, but requires Apache 2.2+ with PHP 5 installed and mod_rewrite enabled.</p>
<p><strong>Single machine configuration</strong><br />
The easiest way to get started is to drop the contents of the package into the <code>C:\</code> drive. </p>
<p><img src="http://www.askaboutphp.com/wp-post-images/71/webpagetest-1.jpg" alt="" /></p>
<p>Configure your Apache to point the document root to <code>C:/Web Site/content</code> folder. If you, like me, had problems loading the site, make sure you check that the Apache modules &#8211; mod_rewrite, mod_expires and mod_headers have been enabled.</p>
<p>Once you have the site setup, the next thing to do is to prepare the tester program, called <code>urlblast.exe</code>. Open the <code>C:\Web Site\urlblast.ini</code> config file and look for the following:</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/71/webpagetest-3.jpg" alt="" /></p>
<p>If your site is NOT running on <code>http://localhost/</code> or <code>http://127.0.0.1/</code>, then you need to change the highlighted line to your site&#8217;s URL. </p>
<p>Once that&#8217;s done, save your the ini file and execute the <code>urlblast.exe</code> program. The first time this program starts, it may open a hard disk defrag window. Just let it run until its done. Once the defrag is done and your urlblast program window is sitting idling, you can go to your site and post an URL to test under the &#8220;New Test&#8221; tab.</p>
<p>If all goes well, your IE should fire up by itself and load the page that you want to test, and then close itself. By default (assuming you didn&#8217;t change any test parameters), this will happen twice as the program tests for &#8220;First View&#8221; loading followed by &#8220;Repeat View&#8221; loading.</p>
<p>If you opt to change the default folder location from <code>C:\Web Site</code> to something else, you just need to update your apache conf file and change the settings within locations.ini in the <code>content/settings/</code> folder to reflect the new location.</p>
<p><strong>Multiple machines configuration</strong><br />
In many cases, a single machine setup is good enough. But, if you have different locations within your network you want to test from, or you want to test different connection speed from the same location, you would need to setup multiple testers.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/71/webpagetest-5.jpg" alt="" /></p>
<p>Assuming a setup like above, with one machine running the WebPageTest website, accessed through <code>http://webpagetest/</code> and two machines as testers, <code>Test1</code> and <code>Test2</code>. It is important that the website be setup so that it can be accessed from another machine. The 2 tester units needs to be able to see the website. In this case, a &#8216;<em>webpagetest</em>&#8216; local domain name was setup. Alternatively, you should be able to access the site through the website&#8217;s IP address. </p>
<p>First, create two new folders inside <code>content/work/jobs</code> folder called <code>Test1</code> and <code>Test2</code> to reflect the 2 tester location. This is where the jobs are queued for each tester.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/71/webpagetest-6.jpg" alt="" /></p>
<p>Next, open the <code>locations.ini</code> file in the <code>content/settings/</code> folder and add 2 new tester locations. Notice that the localDir parameter is set to the respective job folder.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/71/webpagetest-7.jpg" alt="" /></p>
<p>You should be able to see these new location reflected in the website.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/71/webpagetest-8.jpg" alt="" /></p>
<p>What&#8217;s left is to setup the 2 tester units. Copy the <code>pagetest.dll</code>, <code>urlblast.exe</code>, <code>urlblast.ini</code> and the <code>log</code> folder to a folder (assuming its <code>C:\Web Site</code>) on each tester machines.</p>
<p>Open the <code>urlblast.ini</code> for each tester and modify the <code>Url Files Url</code> and <code>Location</code> parameter. If you have changed the &#8220;Location Key&#8221;, make sure it matches the key specified in the location.ini on the website machine. For tester 1 location, it should be like so. Make the change to the tester 2 ini file also.</p>
<p><img src="http://www.askaboutphp.com/wp-post-images/71/webpagetest-9.jpg" alt="" /></p>
<p>To start, just activate the <code>urlblast.exe</code> program on each tester machine, then go to the website and specify a url to test and choose either tester locations. If everything is ok, IE on the designated tester should fire up and start loading the webpage you want to test.</p>
<p>That&#8217;s it. Once I got this setup, the tool has been a great help to my team as we troubleshoot and improve our page loading time. I hope it will be for you too.</p>
<p>Check out this great video tutorial from Artz as he guides you through <a href="http://www.artzstudio.com/2008/07/optimizing-web-performance-with-aol-pagetest/">how to interpret the graphs and charts</a>. Also, do visit <a href="http://blog.patrickmeenan.com/">Pat&#8217;s blog</a> for tips and insights on webpage optimization.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/YPJcoqn2lFz4G_CIW2B-y1XYdIc/0/da"><img src="http://feedads.g.doubleclick.net/~a/YPJcoqn2lFz4G_CIW2B-y1XYdIc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/YPJcoqn2lFz4G_CIW2B-y1XYdIc/1/da"><img src="http://feedads.g.doubleclick.net/~a/YPJcoqn2lFz4G_CIW2B-y1XYdIc/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=4cuzzhIe1tE:wcBvwkN0X0w:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=4cuzzhIe1tE:wcBvwkN0X0w:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=4cuzzhIe1tE:wcBvwkN0X0w:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=4cuzzhIe1tE:wcBvwkN0X0w:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=4cuzzhIe1tE:wcBvwkN0X0w:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=4cuzzhIe1tE:wcBvwkN0X0w:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=4cuzzhIe1tE:wcBvwkN0X0w:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=4cuzzhIe1tE:wcBvwkN0X0w:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AskAboutPhp?a=4cuzzhIe1tE:wcBvwkN0X0w:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/AskAboutPhp?i=4cuzzhIe1tE:wcBvwkN0X0w:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AskAboutPhp/~4/4cuzzhIe1tE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.askaboutphp.com/71/webpagetest-tool-the-little-known-but-great-webpage-benchmarking-tool.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.askaboutphp.com/71/webpagetest-tool-the-little-known-but-great-webpage-benchmarking-tool.html</feedburner:origLink></item>
	</channel>
</rss>
