<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gEt DoWn ToNiGhT &#187; Programming</title>
	<atom:link href="http://www.getdowntonight.co.uk/category/science-technology/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.getdowntonight.co.uk</link>
	<description>amusingly digressive progressive discussions</description>
	<lastBuildDate>Mon, 05 Dec 2011 22:41:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Sample Page for sending JSON data as string to web-service</title>
		<link>http://www.getdowntonight.co.uk/2011/12/sample-page-for-sending-json-data-as-string-to-web-service/</link>
		<comments>http://www.getdowntonight.co.uk/2011/12/sample-page-for-sending-json-data-as-string-to-web-service/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 16:56:04 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[sample]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=569</guid>
		<description><![CDATA[Just realised it has been a year since I posted anything on here! Time really flies when you&#8217;re busy! I remember when I was first starting off with jQuery, JSON and all that jazz that I struggled to find some simple examples of how to do things like send data to a web-service. Here is [...]]]></description>
			<content:encoded><![CDATA[<p>Just realised it has been a year since I posted anything on here! Time really flies when you&#8217;re busy!</p>
<p>I remember when I was first starting off with jQuery, JSON and all that jazz that I struggled to find some simple examples of how to do things like send data to a web-service. </p>
<p>Here is a quick example of how to send some JSON data (as a single post field) to a web service, using jQuery&#8217;s post method. </p>
<p>Keep in mind that if you are posting to another domain you may need to use something called jsonP &#8211; but if you are just learning, this is a good starting point!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;JSON Web Service Demo&lt;/title&gt;
&nbsp;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
&nbsp;
        &lt;script src=&quot;http://code.jquery.com/jquery-1.7.1.min.js&quot;&gt;&lt;/script&gt;
&nbsp;
        <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
            $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">//this code will be added to the onclick event</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#save_user_button'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">//add the values we need for the API to an object</span>
                    <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">//build the object</span>
                    data.<span style="color: #660066;">guid</span>                   <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#guid'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    data.<span style="color: #660066;">defaultallocation</span>      <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#projecttype'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    data.<span style="color: #660066;">email</span>                  <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    data.<span style="color: #660066;">username</span>               <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#username'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    data.<span style="color: #660066;">fullname</span>               <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fullname'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">//turn the object in to a JSON string</span>
                    <span style="color: #003366; font-weight: bold;">var</span> myJson <span style="color: #339933;">=</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://testurl/service/user&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">//call the post</span>
                    $.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>jsonUser <span style="color: #339933;">:</span> myJson<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>myResult<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>myResult<span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div&gt;
            &lt;table&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;Project Type&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;projecttype&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;GUID&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;guid&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;User Name&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;username&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;Full Name&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;fullname&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
                &lt;tr&gt;
                    &lt;td&gt;Email&lt;/td&gt;
                    &lt;td&gt;&lt;input id=&quot;email&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
&nbsp;
            &lt;/table&gt;
&nbsp;
            &lt;input type=&quot;button&quot; id=&quot;save_user_button&quot; value=&quot;Save&quot;/&gt;
&nbsp;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2011/12/sample-page-for-sending-json-data-as-string-to-web-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slow and Locked MySQL Queries</title>
		<link>http://www.getdowntonight.co.uk/2010/12/slow-and-locked-mysql-queries/</link>
		<comments>http://www.getdowntonight.co.uk/2010/12/slow-and-locked-mysql-queries/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 17:08:59 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Science and Tech]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[upgrade]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=498</guid>
		<description><![CDATA[One of our clients&#8217; servers recently saw a huge drop in speed. None of the hardware had been changed, and while the total number of users has been steadily increasing for the last few years, it has not seen any kind of spike that I thought might cause this type of problem. In order to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.getdowntonight.co.uk/wp-content/mysql2.png"><img class="alignright size-thumbnail wp-image-394 colorbox-498" title="mysql2" src="http://www.getdowntonight.co.uk/wp-content/mysql2-150x150.png" alt="" width="90" height="90" /></a>One of our clients&#8217; servers recently saw a huge drop in speed. None of the hardware had been changed, and while the total number of users has been steadily increasing for the last few years, it has not seen any kind of spike that I thought might cause this type of problem.</p>
<p>In order to try to find the fault or problem, I had to look in many different places and discovered a lot about Linux and MySQL. I enjoy these fact finding missions, even though there are always a lot of dead ends.</p>
<p>I thought I would use this blog as a place to write down all the areas that are worth checking, in case anyone else finds themselves in this situation.</p>
<p>Things to check:</p>
<ul>
<li>The Process List</li>
<li>MySQL Slow Query Log</li>
<li>Server free disk space</li>
<li>Server memory usage</li>
<li>Server load</li>
<li>Your queries</li>
<li>Your indexes</li>
</ul>
<p>Our server was running on Linux Centos 3, and many of the commands below are Linux only. For executing the MySQL commands and queries I suggest getting something like WebYog&#8217;s excellent<a href="http://www.webyog.com/en/downloads.php" target="_blank"> SQLYog</a>, or using MySQL&#8217;s own <a href="http://dev.mysql.com/downloads/workbench/5.2.html" target="_blank">MySQL Workbench</a>.</p>
<p><strong>Listing active MySQL queries<br />
</strong></p>
<p>MySQL contains the ability to show a list of currently running queries. From within MySQL &#8211; execute the following query:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SHOW</span> PROCESSLIST<span style="color: #000033;">;</span></pre></div></div>

<p>This will show a list that details which users, hosts, databases are being used to execute queries &#8211; how long they have been going for, and what state they are in. Look for queries that have been running for a long time, or have the state of &#8216;locked&#8217;. For more information <a href="http://dev.mysql.com/doc/refman/5.5/en/show-processlist.html" target="_blank">see here</a>.</p>
<p><strong>Breaking down your queries</strong></p>
<p>It is crucial that you enable slow query logging and it is quite simple to set up. Edit your my.cnf file, and make sure the following is present:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">log-slow-queries = /var/log/mysql/mysql-slow.log
long_query_time = 3</pre></div></div>

<p>(Adjust the log_query_time setting to suit the length of the query you are trying to detect)</p>
<p>Once this is in place, restart the MySQL server and start checking the new log file.</p>
<p>The MySQL command <a href="http://dev.mysql.com/doc/refman/5.1/en/using-explain.html" target="_blank">EXPLAIN</a> allows you to see a breakdown of the steps taken by MySQL to get your query results, including information about joins and the sequence of queries called. You can use the information it outputs to help optimise your own queries.</p>
<p>The utility is easy to use. Simply prefix your SELECT statement with the word EXPLAIN. eg.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">EXPLAIN</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> userName<span style="color: #000033;">,</span> firstName<span style="color: #000033;">,</span> lastName
<span style="color: #990099; font-weight: bold;">FROM</span> users
<span style="color: #990099; font-weight: bold;">WHERE</span> firstName <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">'da<span style="color: #008080; font-weight: bold;">%</span>'</span><span style="color: #000033;">;</span></pre></div></div>

<p><strong>top</strong><a href="http://www.getdowntonight.co.uk/wp-content/Screen-shot-2010-12-17-at-16.53.07.png"><img class="alignright size-thumbnail wp-image-499 colorbox-498" title="Output from the Linux top command" src="http://www.getdowntonight.co.uk/wp-content/Screen-shot-2010-12-17-at-16.53.07-150x150.png" alt="" width="150" height="150" /></a></p>
<p>This command shows you a list of applications and services running on the machine, along with some basic information about the resources they are using.</p>
<p>From here you can see the system load, free memory and the % of CPU for each process.</p>
<p>To quit and return to the shell, use CTRL+C.</p>
<p><strong>df -h</strong></p>
<p>This will show you how much free space is on your mounted drives, in human readable form.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">[sam@webserver1 /]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/md1              9.8G  3.9G  5.9G  40% /
none                 1014M     0 1014M   0% /dev/shm
/dev/md2               57G   31G   27G  54% /disk1</pre></div></div>

<p><strong>tail</strong></p>
<p>This is a quick way of looking at the last few lines of a log file. The following will show you the last 10 lines of the mysql log.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">tail /var/log/mysql.log</pre></div></div>

<p>You can also specify that you want to view a specific number of lines by using the -n parameter. eg.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">tail -n 50 /var/log/mysql.log</pre></div></div>

<p>Eventually, after going through lots of checking and tests, we discovered that the server was simply at capacity. It hadn&#8217;t been upgraded for 8 years and the number of users had quadrupled during that time &#8211; with users from 2 other continents now logging on regularly. The database was on the same hardware as the web-server software and the system was just becoming overloaded.</p>
<p>We managed to speed things up considerably before we were forced to upgrade, mostly by examining the slow-query-log and adding indexes where appropriate. Also, many of our queries were refined and tidied up &#8211; so we were definitely not wasting our time running the examinations. It has made me realise that it is probably worth going back over old code every now and then to check for potential improvements &#8211; something we only tend to do if there is a client requirement, or an OS upgrade required.</p>
<p>We have now performed a complete upgrade to the latest hardware available, with 8GB of memory, more CPU cores than I suspect are really needed, the latest Centos 5 OS and all the most recent MySQL/Apache and PHP versions &#8211; which has made the system run incredibly quickly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2010/12/slow-and-locked-mysql-queries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using the database from inside a helper (CodeIgniter)</title>
		<link>http://www.getdowntonight.co.uk/2010/06/using-the-database-from-inside-a-helper-codeigniter/</link>
		<comments>http://www.getdowntonight.co.uk/2010/06/using-the-database-from-inside-a-helper-codeigniter/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 09:06:17 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=468</guid>
		<description><![CDATA[I have some custom functions that I store in a helper in CodeIgniter. Some of those functions need to use the database, and to do so you have to explicitly tell the function to load the Code Igniter framework and database class. Its pretty simple when you know how, but it took quite a while [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright colorbox-468" title="CodeIgniter Logo" src="http://herloct.files.wordpress.com/2009/05/ci_logo_flame.jpg" alt="" width="90" height="98" />I have some custom functions that I store in a helper in CodeIgniter. </p>
<p>Some of those functions need to use the database, and to do so you have to explicitly tell the function to load the Code Igniter framework and database class.</p>
<p>Its pretty simple when you know how, but it took quite a while to work it out.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_user_full_name<span style="color: #009900;">&#40;</span><span style="color: #000088;">$userId</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//the database functions can not be called from within the helper</span>
    <span style="color: #666666; font-style: italic;">//so we have to explicitly load the functions we need in to an object</span>
    <span style="color: #666666; font-style: italic;">//that I will call ci. then we use that to access the regular stuff.</span>
    <span style="color: #000088;">$ci</span><span style="color: #339933;">=&amp;</span> get_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$ci</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">database</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//select the required fields from the database</span>
    <span style="color: #000088;">$ci</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'firstName, lastName'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//tell the db class the criteria</span>
    <span style="color: #000088;">$ci</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'userId'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$userId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//supply the table name and get the data</span>
    <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ci</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//ensure that there is something in the variable - in case of no match</span>
    <span style="color: #000088;">$fullName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//get the full name by concatinating the first and last names</span>
        <span style="color: #000088;">$fullName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">firstName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lastName</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// return the full name;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$fullName</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2010/06/using-the-database-from-inside-a-helper-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Eclipse as a PHP IDE in Ubuntu 9.10</title>
		<link>http://www.getdowntonight.co.uk/2009/11/using-eclipse-as-a-php-ide-in-ubuntu-9-10/</link>
		<comments>http://www.getdowntonight.co.uk/2009/11/using-eclipse-as-a-php-ide-in-ubuntu-9-10/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 17:05:40 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=405</guid>
		<description><![CDATA[This is actually much easier than any of the guides I found online make out. Firstly, install Eclipse from the repositories. Then open it up, select your default workspace (if you havent already) and then: From the Help menu, select &#8220;Install new software&#8221;. Click the &#8220;Add&#8221; button and add the following: Name: Eclipse Updates (Galileo) [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright colorbox-405" src="http://wwwbruegge.informatik.tu-muenchen.de/twiki/pub/Lehrstuhl/SysiphusGoesEclipse/eclipse.png" alt="" width="90" height="90" />This is actually much easier than any of the guides I found online make out.</p>
<p>Firstly, install <strong>Eclipse</strong> from the repositories. Then open it up, select your default workspace (if you havent already) and then:</p>
<ol>
<li>From the Help menu, select &#8220;Install new software&#8221;.</li>
<li>Click the &#8220;Add&#8221; button and add the following:
<ol></ol>
<ul>
<li><strong>Name</strong>: Eclipse Updates (Galileo)</li>
<li><strong>Location</strong>: http://download.eclipse.org/releases/galileo/</li>
</ul>
<ol></ol>
</li>
<li>Apply your changes and wait for the contents to download.</li>
<li>When all is ready, select your new source from the drop down and look for the &#8220;Programming languages&#8221; section.</li>
<li>Open it up and add the &#8220;PHP Development Tools (PDT) SDK Feature&#8221;.</li>
<li>Step through using Next and Finish etc, and after a few moments downloading and installing you now have a PHP ready IDE.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/11/using-eclipse-as-a-php-ide-in-ubuntu-9-10/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Loading JSON data &#8211; the EASY way!</title>
		<link>http://www.getdowntonight.co.uk/2009/11/loading-json-data-the-easy-way/</link>
		<comments>http://www.getdowntonight.co.uk/2009/11/loading-json-data-the-easy-way/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 12:22:04 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=398</guid>
		<description><![CDATA[A few weeks ago I wrote a blog post about using jQuery and JSON to automatically load data from a JSON file in to name-matched controls on an HTML page. It is only now that I realise quite how powerful this is! The great thing about it is that you do not have to edit [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-403 colorbox-398" title="json160" src="http://www.getdowntonight.co.uk/wp-content/json160.gif" alt="json160" width="96" height="96" />A few weeks ago I wrote a blog post about using jQuery and JSON to automatically load data from a JSON file in to name-matched controls on an HTML page.</p>
<p><strong>It is only now that I realise quite how powerful this is!</strong></p>
<p>The great thing about it is that you do not have to edit your data-load function if you add a new field to the database. Because the jQuery function loops through all the fields in the JSON data, it will automatically insert the values in to the correct fields, providing those fields are named the same as the html form controls.</p>
<p>Here is the code again for those who dont want to check back.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/yourJson.js, function(myJson){
	$.each(myJson.rows, function(i,item) {
		 for (prop in item) {
		 	 $('#' + prop).val(item[prop]);
		 }
	});
});</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/11/loading-json-data-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing MyODBC 3.51 on Windows 7 x64</title>
		<link>http://www.getdowntonight.co.uk/2009/11/installing-myodbc-3-51-on-windows-7-x64/</link>
		<comments>http://www.getdowntonight.co.uk/2009/11/installing-myodbc-3-51-on-windows-7-x64/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 11:11:44 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[64 bit]]></category>
		<category><![CDATA[connector]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[myodbc]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[windows 7]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=393</guid>
		<description><![CDATA[In order to get some of our 32 bit applications working on Windows 7 64 bit edition, we need to provide support for the MySQL 3.51 ODBC connector. This is actually quite simple to do, as long as you know what to look for. The ODBC manager that you are able to access from within [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-394 colorbox-393" title="mysql2" src="http://www.getdowntonight.co.uk/wp-content/mysql2.png" alt="mysql2" width="105" height="105" />In order to get some of our 32 bit applications working on Windows 7 64 bit edition, we need to provide support for the <a href="http://dev.mysql.com/downloads/connector/odbc/3.51.html" target="_blank">MySQL 3.51 ODBC</a> connector.</p>
<p>This is actually quite simple to do, as long as you know what to look for. The ODBC manager that you are able to access from within Windows is not going to work for you, but it turns out that Microsoft provide a 32 bit manager that will.</p>
<p>To use this manager, run the following command:</p>
<p><strong>c:\windows\syswow64\odbcad32.exe</strong></p>
<p>Please note that it is not good enough to just type odbcad32.exe, as there is another file in the path with the same file name (great work MS!). However, once you have opened this application up, it works in the exact same way as if you were running XP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/11/installing-myodbc-3-51-on-windows-7-x64/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Setting up a basic web server using Ubuntu 9.10 (Desktop)</title>
		<link>http://www.getdowntonight.co.uk/2009/11/setting-up-a-basic-web-server-using-ubuntu-9-10-desktop/</link>
		<comments>http://www.getdowntonight.co.uk/2009/11/setting-up-a-basic-web-server-using-ubuntu-9-10-desktop/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 17:14:08 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[web server]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=366</guid>
		<description><![CDATA[I have been using Ubuntu 9.10 for a while and wanted to see how it performs as a web server. The GUI interface is very slick and it is an ideal OS for beginners and advanced users alike. I suspect that many people will want to use it as the basis for their webservers. I [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-390 colorbox-366" title="Ubuntu Logo" src="http://www.getdowntonight.co.uk/wp-content/jaustin_saturated_full_logo_021_trans-300x88.png" alt="Ubuntu Logo" width="180" height="53" />I have been using Ubuntu 9.10 for a while and wanted to see how it performs as a web server. The GUI interface is very slick and it is an ideal OS for beginners and advanced users alike. I suspect that many people will want to use it as the basis for their webservers.</p>
<p>I suggest creating a virtual machine with something like VirtualBox for this. It is much more flexible that way, and you can move it to a more powerful machine if you decide you need to.</p>
<p><strong>Phase 1. Install required applications:</strong></p>
<ol>
<li>Open &#8216;Synaptic package manager&#8217; from the System/Administration menu.</li>
<li>Click the &#8216;Search&#8217; button.</li>
<li>Enter &#8216;Apache&#8217; and press return.</li>
<li>You will see an item called &#8216;Apache2&#8242; in the list of results. Click the box to the left to mark it as something you want to install.</li>
<li>Repeat this process for:
<ul>
<li>Php5</li>
<li>MySql</li>
<li>Php5-mysql</li>
</ul>
</li>
<li>Click the &#8216;Apply&#8217; button on the toolbar.</li>
<li>This will start the installation process, during which you will be prompted to provide a password for the MySQL root account. Supply a strong password and make sure you do not forget it.</li>
<li><img class="alignright size-medium wp-image-374 colorbox-366" title="It worked!" src="http://www.getdowntonight.co.uk/wp-content/Screenshot-WebServer-1-Ubuntu-9.10-Running-VirtualBox-OSE-1-300x227.png" alt="It worked!" width="180" height="136" />When everything has finished installing, I suggest rebooting. There are ways of starting the servers without rebooting, but a reboot works just as well and is much easier.</li>
<li>After you have logged back in to Ubuntu, open up Firefox and visit http://localhost.</li>
<li>You should see a page that says &#8220;It works!&#8221; which means that your webserver is now working.</li>
</ol>
<p><strong>Phase 2: Configure Virtual Hosts</strong> (So you can have more than one site on your server)</p>
<p>I have chosen to use the command line to do much of this phase rather than the GUI. For me, it is much easier to access protected system files from the shell rather than use a GUI. However, should you want to use a GUI, you will need to be running with root privileges. You can do this by entering: <strong>sudo nautilus</strong> in to a command line (and enter your password). However, the instructions below are for using the shell.</p>
<p><em>Any time you see the <strong>sudo</strong> command, that means that you will run the command as root (administrator). Linux is much more secure than Windows thanks to it being locked down by default with a standard set of permissions. It might seem like hassle to keep having to switch to be administrator but it makes things much safer. Deal with it!</em></p>
<ol>
<li>Open a new Terminal from Applications / Accessories in the menus.</li>
<li>In the terminal, enter the following commands and review the results so you know what you are doing.</li>
<li><strong>cd /etc/apache2/sites-enabled</strong> (<em>this moves you to the folder where you can define different websites</em>)</li>
<li><strong>ls</strong> (<em>lower case LS: this will show you a list of files</em>)</li>
<li><strong>sudo cp 000-default 001-mysite</strong> (<em>this will copy the default config file so you can use it as the basis for your new site</em>)</li>
<li>Enter your password when prompted (<em>this should only happen once, but if you are prompted again &#8211; just re-enter it</em>)</li>
<li><strong>sudo gedit 001-mysite</strong> (<em>this will use the gedit text editor to open and allow you to edit the new site config file</em>)</li>
<li>Change the <strong>ServerAdmin</strong> row to use your email address. ie. <strong>ServerAdmin sam@mysite.net</strong></li>
<li>Add a row below with the tag: <strong>ServerName</strong> followed by the name of your site. I will continue to use <strong>mysite.local</strong> throughout. ie. <strong>ServerName mysite.local</strong></li>
<li>Edit the row <strong>DocumentRoot</strong> so that the new path is a sub-folder of www called 001-mysite. ie. <strong>/var/www/001-mysite</strong></li>
<li>Edit the row <strong>&lt;Directory&#8230;&gt;</strong> so that the new path is also used. ie. <strong>&lt;Directory /var/www/001-mysite&gt;</strong></li>
<li>Save the file and closed GEdit.</li>
<li><img class="alignright size-medium wp-image-385 colorbox-366" title="A working PHP virtual host" src="http://www.getdowntonight.co.uk/wp-content/Screenshot-WebServer-1-Ubuntu-9.10-Running-VirtualBox-OSE-2-300x227.png" alt="A working PHP virtual host" width="180" height="136" />We now need to let your computer know that it IS mysite.local. The easiest way to do this is to edit your <strong>hosts</strong> file. There is plenty of information <a href="http://en.wikipedia.org/wiki/Hosts_file" target="_blank">online</a> about what this file does.</li>
<li>From the terminal, type: <strong>sudo gedit /etc/hosts</strong></li>
<li>Add a new row below <strong>127.0.0.1    localhost</strong> that reads: <strong>127.0.0.1     mysite.local</strong> (spaces are tabs)<strong>.<br />
</strong></li>
<li>Save the file and close GEdit.</li>
<li>Now we need to create the file structure for where the sites files will live.</li>
<li>Enter: <strong>sudo mkdir /var/www/001-mysite</strong> (this will create a new folder that will store your php/html files etc)<strong><br />
</strong></li>
<li><strong>cd /var/www/001-mysite<br />
</strong></li>
<li><strong>sudo gedit index.php</strong> (this will open the text editor again and will allow you to create the index page for your site).</li>
<li>In the text editor, enter the following bold text (including all the punctuation): <strong>&lt;?php phpinfo(); ?&gt;</strong></li>
<li>Save the file and close.</li>
<li><strong>sudo /etc/init.d/apache2 restart</strong> (this restarts the Apache service so that the new virtual host is available)<strong><br />
</strong></li>
<li>Now open firefox and visit your new site: http://mysite.local</li>
<li>You should see a whole load of information about your server, and more specifically about your PHP installation.</li>
<li>Thats it! Repeat this phase to add as many virtual hosts as you like.</li>
</ol>
<p>You will now almost certainly want to secure your server. If you have got this far then you can at least get your site(s) up and running on your local machine. Ill cover securing your server in another post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/11/setting-up-a-basic-web-server-using-ubuntu-9-10-desktop/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Inserting JSON data in to name-matched controls</title>
		<link>http://www.getdowntonight.co.uk/2009/09/inserting-json-data-in-to-name-matched-controls/</link>
		<comments>http://www.getdowntonight.co.uk/2009/09/inserting-json-data-in-to-name-matched-controls/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 12:08:10 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=348</guid>
		<description><![CDATA[Thought this might be handy&#8230; This loop will insert the values from a JSON object in to text boxes. It loops around each key-pair and inserts the value if there is a text box with an ID that matches the key name. This is the JSON data: (yourJson.js) &#123;&#34;page&#34;:1,&#34;total&#34;:1,&#34;records&#34;:1,&#34;paging&#34;:20,&#34;rows&#34;:&#91; &#123;&#34;clipId&#34;:&#34;14792&#34;,&#34;barcode&#34;:&#34;02528&#34;,&#34;title&#34;:&#34;My Project Sample&#34;,&#34;format&#34;:&#34;DigiBeta&#34;,&#34;source&#34;:&#34;1242&#34;, &#34;runningTime&#34;:&#34;14 Mins&#34;,&#34;location&#34;:&#34;Library&#34;,&#34;timeCode&#34;:&#34;10:00:00&#34;,&#34;cUser&#34;:&#34;Sam&#34;, &#34;cDate&#34;:&#34;1 [...]]]></description>
			<content:encoded><![CDATA[<p>Thought this might be handy&#8230; This loop will insert the values from a JSON object in to text boxes.</p>
<p>It loops around each key-pair and inserts the value if there is a text box with an ID that matches the key name.</p>
<p>This is the JSON data: (yourJson.js)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;page&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;total&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;records&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;paging&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;rows&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;clipId&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;14792&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;barcode&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;02528&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;My Project Sample&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;format&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;DigiBeta&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;source&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;1242&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;runningTime&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;14 Mins&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;location&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Library&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;timeCode&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;10:00:00&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;cUser&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Sam&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;cDate&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;1 Jan 2007&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;mUser&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Sam&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;mDate&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;1 Jan 2008&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is the form HTML:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>form<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>table<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>Clip Id<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">'clipId'</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>Barcode<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">'barcode'</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>Title<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>Format<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">'format'</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>Source<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">'source'</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>Running Time<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">'runningTime'</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>Location<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">'location'</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>Time Code<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">'timeCode'</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span></pre></div></div>

<p>This is the jQuery:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/yourJson.js, function(myJson){
		$.each(myJson.rows, function(i,item) {
		    for (prop in item) {
				$('#' + prop).val(item[prop]);
		    }
		}); 
	});</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/09/inserting-json-data-in-to-name-matched-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating JSON data from MySQL in PHP</title>
		<link>http://www.getdowntonight.co.uk/2009/08/creating-json-data-from-mysql-in-php/</link>
		<comments>http://www.getdowntonight.co.uk/2009/08/creating-json-data-from-mysql-in-php/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 16:43:50 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=331</guid>
		<description><![CDATA[Here is a quick post that demonstrates how to create some neat JSON data from MySQL using PHP. The script is really simple, and has been working well for me over the last few weeks. If anything is confusing, it might be worth checking out the previous post about creating XML data from PHP. It [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick post that demonstrates how to create some neat JSON data from MySQL using PHP. The script is really simple, and has been working well for me over the last few weeks. </p>
<p>If anything is confusing, it might be worth checking out the previous post about creating XML data from PHP. It explains things in more detail and will help if you are not familiar&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//set up the php headers so that the page doesnt cache etc</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Last-Modified: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;D, d M Y H:i:s&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; GMT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: no-cache, must-revalidate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pragma: no-cache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">total</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$totalPages</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$recordCount</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$countRows</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'userAccountId'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'userName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'userName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fullName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fullName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'accessCode'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'accessCode'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</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: #000088;">$row</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: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'addedBy'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'addedBy'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'addedDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'addedDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'modifiedBy'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'modifiedBy'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$jsonArray</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'modifiedDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'modifiedDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span> 
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$jsonArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The above code will create the following style JSON output.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;page&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;total&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;records&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;3&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;rows&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;userName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;demo&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;fullName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Demo User&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;accessCode&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;email&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;demo@myexample.com&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;addedBy&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;addedDate&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2009-05-02 00:00:00&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;modifiedBy&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;10&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;modifiedDate&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2009-06-04 00:00:00&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;userName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;sam&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;fullName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Sam Lasagne&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;accessCode&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;email&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;sam@myexample.com&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;addedBy&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;addedDate&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2009-05-02 00:00:00&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;modifiedBy&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;modifiedDate&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2009-08-02 00:00:00&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;10&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;userName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;adrian&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;fullName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Adrian Spaghetti&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;accessCode&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;email&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;adrian@myexample.com&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;addedBy&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;addedDate&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2009-05-02 00:00:00&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;modifiedBy&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;modifiedDate&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;2009-09-01 00:00:00&quot;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/08/creating-json-data-from-mysql-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using XML in your jQuery to populate input boxes</title>
		<link>http://www.getdowntonight.co.uk/2009/08/using-xml-in-your-jquery-to-populate-input-boxes/</link>
		<comments>http://www.getdowntonight.co.uk/2009/08/using-xml-in-your-jquery-to-populate-input-boxes/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 18:06:13 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Science and Tech]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.getdowntonight.co.uk/?p=311</guid>
		<description><![CDATA[In a previous post I wrote about creating XML pages with MySQL data, using PHP. In this article, I&#8217;ll explain in simple terms how to parse that XML data and insert some of its values in to your page using jQuery. I&#8217;m going to keep this very simple, as there seem to be very few [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://www.getdowntonight.co.uk/2009/07/creating-xml-in-php/">previous post</a> I wrote about creating XML pages with MySQL data, using PHP. In this article, I&#8217;ll explain in simple terms how to parse that XML data and insert some of its values in to your page using jQuery.</p>
<p>I&#8217;m going to keep this very simple, as there seem to be very few examples of this on the net. It took me a while to work out a neat way of doing this, and I&#8217;m sure someone can improve on things. If so &#8211; please let me know in the comments.</p>
<p>First, lets set up an example. A very simple example. </p>
<p>Imagine an invoice. 4 boxes at the top of a grid, with a &#8216;Save&#8217; button that will add the contents of those boxes to the list below. The fields are such as &#8216;Item code&#8217;, &#8216;Description&#8217;, &#8216;Quantity&#8217; and &#8216;Unit Price&#8217;. The user enters the values and clicks the &#8216;Save&#8217; button to add that row to the list and clear the boxes, ready for the next row to be added. For the purposes of what we are doing, we will also want a 5th box (which would usually be hidden) to store the &#8216;Invoice Detail Id&#8217;.</p>
<p>Something like this:</p>
<pre>
<div class="wp_syntax">
<table>
<tr>
<td>Code
<input id="code" size='5'></td>
<td>Description
<input id="description"></td>
<td>Quantity
<input id="quantity" size='5'></td>
<td>Price
<input id="unitPrice" size='5'></td>
<td>
<input type='button' value='Save' onClick="alert('Please dont click');"></td>
<td><small>Hidden ID</small>
<input id="invoiceDetailId" size='5'></td>
</tr>
</table>
</div>
</pre>
<p>Creating this application is all quite trivial for someone experienced in PHP. However, what would be nice is to be able to edit each row without having to re-load the page. Well we can do this quickly and easily using jQuery.</p>
<p>Before we start with the jQuery code, we need to have ready a PHP page that will return valid XML with the details of an invoice detail record. Please see my <a href="http://www.getdowntonight.co.uk/2009/07/creating-xml-in-php/">previous post</a> for some help on how to do this.</p>
<p>This is an example output from the getDetailRow.php file.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;invoice<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;invoiceDetail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;invoiceDetailId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/invoiceDetailId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;code<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CR282<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/code<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Software Support<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;unitPrice<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>40<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/unitPrice<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/invoiceDetail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;invoice<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Against each row, add a button labeled &#8216;Edit&#8217;, and attach some jQuery code that calls a function called editDetailRow(detailRowId) &#8211; as the grid is built, insert this code in to each button with the parameter of that row&#8217;s detail ID. </p>
<p>Assuming that there is only ever one result in the XML output, you could use the following code to insert the values in to your input boxes.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> editDetailRow<span style="color: #009900;">&#40;</span>detailId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//first we need to load the XML data for that detail row</span>
    <span style="color: #006600; font-style: italic;">//if the function is a success it will call the function called processDetail</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
       type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
       url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;getDetailRow.php?detailId=&quot;</span> <span style="color: #339933;">+</span> detailId<span style="color: #339933;">,</span>
       dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;xml&quot;</span><span style="color: #339933;">,</span>
       success<span style="color: #339933;">:</span> processDetail
     <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> processDetail<span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//this function gets the results from the xml file</span>
    <span style="color: #006600; font-style: italic;">//and inserts them in to the boxes</span>
    $<span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;invoiceDetail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>   <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#code&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;code&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#description&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#quantity&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;quantity&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#unitPrice&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;unitPrice&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#invoiceDetailId&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;invoiceDetailId&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Yes, it really is that simple. You will need to add a reset button, and make sure you check for a value in the invoiceDetailId when you save (to either call an UPDATE or an INSERT) but thats it.</p>
<p>Hopefully you will find this useful and can use this as the basis for much more complicated XML and jQuery hookup&#8217;s.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.getdowntonight.co.uk/2009/08/using-xml-in-your-jquery-to-populate-input-boxes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

