<?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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Adam Oliver's Blog</title>
	
	<link>http://blog.adamoliver.net</link>
	<description>Adam Oliver's blog, portfolio and web tutorials and labs</description>
	<pubDate>Sat, 06 Mar 2010 11:01:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</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/AdamOliversBlog" /><feedburner:info uri="adamoliversblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Choosing The Right Website Hosting Company</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/apcCmo-0lw4/</link>
		<comments>http://blog.adamoliver.net/hosting/choosing-the-right-website-hosting-company/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 10:58:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[hosting]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=736</guid>
		<description><![CDATA[Which hosting company should you choose for your website?]]></description>
			<content:encoded><![CDATA[<p>Over the years I have have used a variety of shared hosting platforms for small websites.  In this article I share my thoughts in what you should look for when you require a hosting company for your website.</p>
<p><span id="more-736"></span></p>
<h4>What to look for</h4>
<p><strong>1. Avoid free website hosting companies<br />
<span style="font-weight: normal;">With website hosting you usually pay for what you get.  Choose a free website host and you are likely to get advertising plastered over your site, slow speeds and poor support.</span></strong></p>
<p><strong>2. Will you be designing and developing the website?<br />
<span style="font-weight: normal;">If you have the knowledge and experience to design and develop your own site you are likely to want to include more features and demand more from your host.  If you are looking for a template builder then there are hosting companies out there that will let you create your own site through a wizzard. They are widely varied in quality and most are proprietary. That means that if you decide at any point you want to move your site elsewhere you’re stuck and are likely to have to start from scratch.</span></strong></p>
<p><strong>3. What level of support will you get?<br />
<span style="font-weight: normal;">Most hosting companies will provide some sort of support.  Whether you are a novice or a seasoned pro, at some point you will require some sort of support.  Even if it is to notify your host that your site is down.  Make sure you read up on how they provide support and to what level. I have had varying levels of support from a quick answering phone support team, to waiting in a queue in support, to online chat support and email support.  If you are looking for a quick resolution for a problem I always find telephone support is best.  Look for companies with a large knowledge base and FAQ’s available online and 24/7 telephone support.</span></strong></p>
<p><strong>4. Will you get email hosting included?<br />
<span style="font-weight: normal;">Loose your old hotmail, AOL and even google email addresses.  Your own domain name email address looks professional and is usually easy to set up with your website host.  This can usually be done at your hosting company - check first though, some may charge extra.  If you are looking for a cheap way to get great email hosting consider <a href="https://www.google.com/a/">Google Apps for Business</a>.</span></strong></p>
<p><strong>5. What bandwidth and storage allowance do you get?<br />
<span style="font-weight: normal;">Hosting companies will usually put a cap on the amount of data / traffic that you can get to your website and a limit on the capacity of storage space for files.  If you intend to have large files like videos on your site or expect a large volume of traffic to your site, make sure your host will be able to cope with it.</span></strong></p>
<p><strong>6. Test the speed of your hosts network.<br />
<span style="font-weight: normal;">A quick and easy way to test the speed of a ho<br />
sting companies network is to ping their servers.  In windows go to start &gt; run and type “command”.  Then enter “ping hostname.com”  When the series of pings finish look at the average ping time. Anything around or below 80 is good.  Anything above 100 is very bad.  Hosts that are located in a different country are likely to be higher.</span></strong></p>
<p><strong>7.  Do you need a dynamic website host?<span style="font-weight: normal;">If you are simply looking to put a brochure site online with 1-20 pages that won’t be updated regularly then the answer is likely no.  If you want a CMS system, Blog, Ecommerce site or some other dynamic website that will allow users to view up to date content that allows them to truely interact with the site then you are likely to need some sort of server sided scripting language on the server and probably access to a database server.  The possibilities are great but the options are most often either php and mySQL on a linux server or ASP.NET and SQL Server on a Windows server.  Each have their own advantages and disadvantages. I’m sure books have been written on the subject - I wont be discussing the reasons for and against here but make sure that if you are using a 3rd party CMS or blog like Joomla, Dot Net Nuke, Wordpress or Drupal that your hosting company meets the requirements of the website application.</span></strong></p>
<p><strong>8. Do you need a dedicated server?<br />
<span style="font-weight: normal;">For most small websites a shared hosting package will be enough to get your website up and running.  For sites with 10GB or more of data and thousands of visitors a day may require a dedicated server.  Look for the amount of RAM offered by the hosting company as well as the speed of the processor.</span></strong></p>
<h4>Advice before you buy</h4>
<p><strong>1. Call the hosting company<br />
<span style="font-weight: normal;">Get a feel for how their customer service is.  Ask for advice on what they would recommend to you.  Call the technical support department.  You will normally get straight through to a sales department but when you need support it is more likely that you will wait in a queue.</span></strong></p>
<p><strong>2. Buy domains from the same company<br />
<span style="font-weight: normal;">If you are buying multiple domains, buy them with the same company.  It doesn’t have to be with the same company as you host with, but managing all your domains in one place will likely save you time in the future.</span></strong></p>
<p><strong>3. Make sure your host satisfies your requirements for setting up DNS.<br />
<span style="font-weight: normal;">I have come across a few hosting companies that will only allow you to edit A records and MX records for the domain and not allow you to add your own custom ones.  If you require the functionality, make sure you check before you buy.</span></strong></p>
<p><strong>4. Search Google for reviews of the company</strong>.<br />
Don’t just go with them because they are cheapest.  It’s usually for a reason.  Do a bit of research first to find out about other people’s experiences with them.</p>
<h4>Recommendations</h4>
<p><a href="http://www.pipeten.com">PipeTen</a><br />
<a href="http://www.fasthosts.co.uk">Fasthosts</a><br />
<a href="http://www.mediatemple.net">Media Temple</a></p>
<p>Share your experience&#8217;s and recommendations for website hosting companies in the comments below.</p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/apcCmo-0lw4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/hosting/choosing-the-right-website-hosting-company/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/hosting/choosing-the-right-website-hosting-company/</feedburner:origLink></item>
		<item>
		<title>Using The Twitter API With PHP and SimpleXML</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/N0snLdH9duc/</link>
		<comments>http://blog.adamoliver.net/tutorials/using-the-twitter-api-with-php-and-simplexml/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 18:00:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=717</guid>
		<description><![CDATA[Find out how to retrieve data from twitter using their API and a little PHP.]]></description>
			<content:encoded><![CDATA[<p>Twitter has opened up a huge array of functionality through the use of it&#8217;s API and it&#8217;s really easy to use. In this tutorial I am going to make use of the API to make a simple search using search phrases as well as hashtags. I&#8217;m going to retrieve the data via XML and parse it using SimpleXML - now built into PHP5 and return the results to the browser.<br />
<span id="more-717"></span></p>
<div class="downloadpanel clearfix">
<div class="left">
<h3>Requirements</h3>
<ul>
<li>A basic knowledge of PHP</li>
<li>Basic knowledge of HTML</li>
</ul>
</div>
<div class="left">
<h3>Demo</h3>
<ul>
<li><a href="http://adamoliver.net/demos/twitter-api/">view demo</a></li>
<li><a href="http://adamoliver.net/demos/twitter-api/twitter-api.zip">download demo</a></li>
</ul>
</div>
</div>
<p>To start with we can have a look at the functionality of the Twitter API on the <a href="http://apiwiki.twitter.com/">Twitter wiki site</a>. Here we can see that we are able to send a query to the search API by using the URL: http://search.twitter.com/search.atom?q= followed by our search term. Twitter makes use of hashtags to tag posts.If we wanted to search for just hash tags we can do that by using the URL version of hash before our query. for example: http://search.twitter.com/search.atom?q=#battlestar gives us posts that contain the hashtag of battlestar. Try it out in your browser.  It will return an XML document containing the results. That was easy! Now we just need to parse the XML with a bit of PHP and format it in a way that is a bit more useful and can be added to our site.</p>
<p>Create a new PHP document and start off by assigning our search term to a local variable. I&#8217;ll also create a variable to hold the number of posts we want to get from Twitter.  I&#8217;ll just get one but you can change that here if you want.</p>
<pre><code>
$searchterm = 'battlestar';
$numberofresults = 1;
</code></pre>
<p>Next up is retrieving the XML document. Using loadXML we can get the XML document and store it into an object.</p>
<pre><code>
$thedom = new DOMDocument;
$thedom-&gt;loadXML(file_get_contents('http://search.twitter.com/search.atom?q=%23'.$searchterm));
if (!$thedom) {
echo 'Error while parsing the document';
exit;
}
$thes = simplexml_import_dom($thedom);
</code></pre>
<p>The XML document is now stored in an object in PHP. If you want to find out what nodes and values are in the object you can print it out to a page using:</p>
<pre><code>echo '&lt;pre&gt;';
print_r($thes);
echo '&lt;/pre&gt;';
</code></pre>
<p>Now we&#8217;re going to declare a local variable called count.  Since we now have the XML document stored in an object in PHP we can itterate through the nodes, now properties and echo out the values.  The count variable will allow us to determine how many items we will display.  I&#8217;ll give the page a heading here as well before we start the loop.</p>
<pre><code>
$count = 0;
echo '&lt;h3&gt;What people are saying on Twitter about #'.$searchterm.'&lt;/h3&gt;';
</code></pre>
<p>Start the foreach loop:</p>
<pre><code>
foreach ($thes-&gt;entry as $entry) :
</code></pre>
<p>&#8230;and then start echoing the values to the page:</p>
<pre><code>
$twitterpost = $entry[0]-&gt;content.'
';
$twitterpost = $twitterpost.'posted on: '.date('d/m/Y', strtotime($entry[0]-&gt;updated)).'
';
$author = $entry[0]-&gt;author-&gt;name;
$author  = preg_replace('/\((.*)\)/', '', $author);
$twitterpost = $twitterpost. 'Posted by: &lt;a href="'.$entry[0]-&amp;gt;author-&amp;gt;uri.'"&gt;'.$author.'&lt;/a&gt;';
</code></pre>
<p>After the heading we are going to get the contents of the first post. $entry[0]-&gt;content gets the content property of the first post. This is what has actually been written to Twitter. The next line uses the same method to get the date the post was created using $entry[0]-&gt;updated. The rest of the code is simply to format the date into a readable format. Next up, we get the author. Notice I&#8217;ve used a regular expression to format the username. The default is to display in the format:  (). All I&#8217;ve done it get rid of everything in the brackets. I&#8217;ve then taken advantage of the author URI property to allow me to link to the authors page.</p>
<p>Notice that I haven&#8217;t actually written anything to the page yet.  I&#8217;ve just concatenated everything into a variable called $twitterpost.  Well now we&#8217;ve got everything we can echo it out.</p>
<pre><code>
echo $twitterpost;
</code></pre>
<p>All that remains is to add to our count, and exit the foreach loop.  Again, if you want to display more than one post then change the value here.</p>
<pre>
<code>$count = $count + 1;
if ($count == 1) {break;}
endforeach;</code></pre>
<p><a class="srcfilesdownload" href="http://adamoliver.net/demos/twitter-api/twitter-api.zip">Download Twitter Search With PHP and SimpleXML</a></p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/N0snLdH9duc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/tutorials/using-the-twitter-api-with-php-and-simplexml/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/tutorials/using-the-twitter-api-with-php-and-simplexml/</feedburner:origLink></item>
		<item>
		<title>The Evolution Of Website Design</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/nsmZWYnDcno/</link>
		<comments>http://blog.adamoliver.net/design/the-evolution-of-website-design/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 18:00:13 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
		
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=703</guid>
		<description><![CDATA[A look at how some website designs have changed over the last decade.]]></description>
			<content:encoded><![CDATA[<p>In the internet&#8217;s relatively short life it has come a long way. From it&#8217;s conception in 1973 by Vinton Cerf to the adoption of multinational companies to social networking sites, now anyone can have their own space on the internet.  This post looks back at how over the last decade some well known companies have changed the design of their website.<br />
<span id="more-703"></span></p>
<p>Most large companies began their journey on the internet in the late 1990&#8217;s but technology of that time was limited and sites would sometimes, at best, have an array of static pages which would have to be manually updated.  Images were sparsely used as internet speeds were not fast enough.  In the days that it would take forever to download any sort of multimedia pages were limited in design. We&#8217;ve come a long way since then. It&#8217;s fun to look back over the old designs of websites that have evolved over the years to sites that are now richly interactive. What will the future hold for web design?</p>
<h3>Apple</h3>
<h4>2000</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/apple-2000.jpg" alt="apple-2000" class="barepic" /></p>
<h4>2003</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/apple-2003.jpg" alt="apple-2003" class="barepic" /></p>
<h4>2007</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/apple-2007.jpg" alt="apple-2007" class="barepic" /></p>
<h4>2010</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/apple-today.jpg" alt="apple-today" class="barepic" /></p>
<h3>BBC</h3>
<h4>2002</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/bbc-2002.jpg" alt="bbc-2002" class="barepic" /></p>
<h4>2004</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/bbc-2004.jpg" alt="bbc-2004" class="barepic" /></p>
<h4>2007</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/bbc-2007.jpg" alt="bbc-2007" class="barepic" /></p>
<h4>2010</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/bbc-today.jpg" alt="bbc-today" class="barepic" /></p>
<h3>Google</h3>
<h4>2000</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/google-2000.jpg" alt="google-2000" class="barepic" /></p>
<h4>2005</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/google-2005.jpg" alt="google-2005" class="barepic" /></p>
<h4>2010</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/google-today.jpg" alt="google-today" class="barepic" /></p>
<h3>McDonalds</h3>
<h4>2001</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/mcdonalds-2001.jpg" alt="mcdonalds-2001" class="barepic" /></p>
<h4>2005</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/mcdonalds-2005.jpg" alt="mcdonalds-2005" class="barepic" /></p>
<h4>2010</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/mcdonalds-today.jpg" alt="mcdonalds-today" class="barepic" /></p>
<h3>Microsoft</h3>
<h4>2001</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/microsoft-2001.jpg" alt="microsoft-2001" class="barepic" /></p>
<h4>2003</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/microsoft-2003.jpg" alt="microsoft-2003" class="barepic" /></p>
<h4>2007</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/microsoft-2007.jpg" alt="microsoft-2007" class="barepic" /></p>
<h4>2010</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/microsoft-today.jpg" alt="microsoft-today" class="barepic" /></p>
<h3>Myspace</h3>
<h4>2003</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/myspace-2003.jpg" alt="myspace-2003" class="barepic" /></p>
<h4>2007</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/myspace-2007.jpg" alt="myspace-2007" class="barepic" /></p>
<h4>2010</h4>
<p><img src="http://blog.adamoliver.net/wp-content/uploads/2010/02/wayback-machine/myspace-today.jpg" alt="myspace-today" class="barepic" /></p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/nsmZWYnDcno" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/design/the-evolution-of-website-design/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/design/the-evolution-of-website-design/</feedburner:origLink></item>
		<item>
		<title>iPhone Contract Expiry On o2 Warning</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/Z9WuLd832GI/</link>
		<comments>http://blog.adamoliver.net/technology/iphone-contract-expiry-on-o2-warning/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 15:15:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[personal]]></category>

		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=694</guid>
		<description><![CDATA[What should you do when your iPhone contract runs out?]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s now 18 months since I got my iPhone and my contract has ran out. Fortunately I realised a few days after my contract was expired that my phone was still working. I thought, no problem, maybe they have just put me on a month by month rolling contract until I change it. Nope!<br />
<span id="more-694"></span></p>
<p>Thankfully I went into an o2 store and found out that I had been placed on a pay as you go contract. Without warning I was now paying a ridiculous amount for calls and even more for data usage.  Now o2 actually have some really great sim only deals on at the moment so I was actually able to switch easily enough onto one of them and save some money. Still, a little warning would have been nice o2!</p>
<p>They made up for it, however, for their great deal on broadband right now. £10 per month for 20Mb connection, unlimited downloads and the first 3 months free on a 12 month contract. Easily beats everyone else out there right now. (offer only applies to current o2 broadband customers and mobile customers)</p>
<p>To find out more about these deals visit the <a href="http://shop.o2.co.uk/sim-only-simplicity">o2 sim only site</a> and <a href="http://broadband.o2.co.uk/home/index.jsp">broadband deals</a>.  If you are an o2 broadband customer, make sure you give customer service a call before your contract runs out and be sure to check to find out when your o2 contract is up or you could find yourself with a hefty bill!</p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/Z9WuLd832GI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/technology/iphone-contract-expiry-on-o2-warning/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/technology/iphone-contract-expiry-on-o2-warning/</feedburner:origLink></item>
		<item>
		<title>Fonts Used In Famous Logos</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/AjkD5nyzpjs/</link>
		<comments>http://blog.adamoliver.net/design/fonts-used-in-famous-logos/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 23:02:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=658</guid>
		<description><![CDATA[Find out which fonts have gone into the creation of the logos we see every day.]]></description>
			<content:encoded><![CDATA[<p>I have taken a keen interest in fonts over the last few years, yet so often we look at the brands of companies and do not even think about the thought that has gone into the making of a logo.  I have looked at over a dozen well known logos to find out which fonts they use. Follow the links to find out more about the fonts and an insight into why they may have been chosen as a suitable base for the branding of these companies.<br />
<span id="more-658"></span></p>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/bbc.jpg" alt="BBC" class="contentleft" /></p>
<h4>BBC - <a href="http://new.myfonts.com/fonts/linotype/gill-sans/">Gill Sans</a></h4>
<p>The BBC adopted the Gill Sans typeface as its corporate typeface in 1997. Find out about the history of the BBC brand on <a href="http://en.wikipedia.org/wiki/History_of_BBC_television_idents">Wikipedia</a>.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/bebo.jpg" alt="Bebo" class="contentleft" /></p>
<h4>Bebo - <a href="http://www.dafont.com/font.php?file=neuropol&#038;page=1&#038;nb_ppp_old=10&#038;text=bebo&#038;nb_ppp=10&#038;psize=m&#038;classt=alpha<br />
">Neuropol</a></h4>
<p>Bebo is a popular social website. Find out about the <a href="http://mashable.com/2007/03/28/bebo-logo/">evolution of their logo on Mashable</a>.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/digg.jpg" alt="Digg" class="contentleft" /></p>
<h4>Digg - <a href="http://www.fontfinder.ws/23100/FFF-Forward.html">FFF Forward</a></h4>
<p>Digg.com brings together the best news, videos and pictures on the web as voted on by the Digg community.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/envato.jpg" alt="Envato" class="contentleft" /></p>
<h4>Envato - <a href="http://www.anrdoezrs.net/click-3572165-10274031?url=http%3A%2F%2Fwww.fonts.com%2Ffindfonts%2Fdetail.htm%3Fpid%3D409034&#038;cjsku=409034<br />
">Agenda Italic</a></h4>
<p>Envato, a self-funded startup with head offices in Melbourne, Australia that launched in 2006. Envato operates digital goods marketplaces including ActiveDen and ThemeForest, the largest marketplaces online for Adobe Flash files and WordPress themes respectively.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/facebook.jpg" alt="Facebook" class="contentleft" /></p>
<h4>Facebook - <a href="http://new.myfonts.com/fonts/processtype/klavika/">Klavika</a></h4>
<p>Founded in February 2004, Facebook is a social utility that helps people communicate more efficiently with their friends, family and coworkers. The company develops technologies that facilitate the sharing of information through the social graph, the digital mapping of people&#8217;s real-world social connections.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/flickr.jpg" alt="Flickr" class="contentleft" /></p>
<h4>Flickr - <a href="http://www.fontshop.com/fonts/downloads/linotype/frutiger_std_complete_vp/<br />
">Frutiger Black</a></h4>
<p>Flickr is almost certainly the best online photo management and sharing application in the world allowing you to show off your favorite photos and videos to the world, securely and privately show content to your friends and family.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/lastfm.jpg" alt="Last FM" class="contentleft" /></p>
<h4>Last.FM - <a href="http://www.vllg.com/KLIM/National/mudTyper+Weights/">National</a></h4>
<p>Last FM is the world’s largest online music catalogue, with free music streaming, videos, pictures, charts, artist biographies, concerts and internet radio.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/linkedin.jpg" alt="Linked In" class="contentleft" /></p>
<h4>Linked In - <a href="http://www.fontshop.com/fonts/singles/creative_alliance/myriad_pro_bold/">Myriad Pro Bold</a></h4>
<p>Linked In is a business-oriented social networking site. Founded in December 2002 and launched in May 2003, it is mainly used for professional networking. As of October 2009, LinkedIn had more than 50 million registered users, spanning more than 200 countries and territories worldwide.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/nettuts.jpg" alt="NetTuts" class="contentleft" /></p>
<h4>Net Tuts - <a href="http://www.anrdoezrs.net/click-3572165-10274031?url=http%3A%2F%2Fwww.fonts.com%2Ffindfonts%2Fdetail.htm%3Fpid%3D201241&#038;cjsku=201241">Lubalin Graph</a></h4>
<p>Envato also operates the tutorial network Tuts+, publishing tutorials on a range of subjects and attracting over four million visitors a month. Other Envato web properties include FreelanceSwitch and AppStorm.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/skype.jpg" alt="Skype" class="contentleft" /></p>
<h4>Sykpe - <a href="http://www.fontshop.com/fonts/singles/linotype/helvetica_rounded_bold/">Helvetica Rounded Bold</a></h4>
<p>With Skype you can make free calls over the internet to other people on Skype for as long as you like, to wherever you like.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/twitter.jpg" alt="Twitter" class="contentleft" /></p>
<h4>Twitter - <a href="http://www2.wind.ne.jp/maniackers/pico.html">Pico Alphabet</a></h4>
<p>Twitter is without a doubt the best way to share and discover what is happening right now.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/vimeo.jpg" alt="Vimeo" class="contentleft" /></p>
<h4>Vimeo - <a href="http://www.dafont.com/Black-Rose.Font">Black Rose</a></h4>
<p>Vimeo is a respectful community of creative people who are passionate about sharing the videos they make. We provide the best tools and highest quality video in the universe.</p>
</div>
<div class="topic">
<img src="http://blog.adamoliver.net/wp-content/uploads/2010/01/logos/youtube.jpg" alt="You Tube" class="contentleft" /></p>
<h4>You Tube - <a href="http://www.fontshop.com/fonts/downloads/linotype/alternate_gothic_com_complete_vp/">Alternate Gothic No. 2</a></h4>
<p>YouTube is a video sharing website on which users can upload and share videos.</p>
</div>
<p class="clear">Find out about some more logo design evolutions of some of the worlds best known brands on <a href="http://www.boredpanda.com/21-logo-evolutions-pepsi-cola-apple-nike-nokia/">boredpanda.com</a></p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/AjkD5nyzpjs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/design/fonts-used-in-famous-logos/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/design/fonts-used-in-famous-logos/</feedburner:origLink></item>
		<item>
		<title>Theme Switcher With PHP Variables In CSS</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/LiNmMowIPeg/</link>
		<comments>http://blog.adamoliver.net/tutorials/theme-switcher-with-php-variables-in-css/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 18:00:38 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[Tutorials]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=611</guid>
		<description><![CDATA[Learn how to use PHP within a CSS file to allow you to  dynamically change the style of your site]]></description>
			<content:encoded><![CDATA[<p>There are many theme switchers out there that do the job just great. Whether you change the theme via a server sided script like PHP or through Javascript most theme switchers do the job of changing the CSS file that styles your content.  But what if you want to just change a few of the styles on the page? What if you only want to have to update just one CSS file?<span id="more-611"></span></p>
<div class="downloadpanel clearfix">
<div class="left">
<h3>Requirements</h3>
<ul>
<li>A basic knowledge of PHP</li>
<li>Basic knowledge of HTML &amp; CSS</li>
</ul>
</div>
<div class="left">
<h3>Demo</h3>
<ul>
<li><a href="http://adamoliver.net/demos/php-variables-in-css/">view demo</a></li>
<li><a href="http://adamoliver.net/demos/php-variables-in-css/php-variables-in-css.zip">download demo</a></li>
</ul>
</div>
</div>
<p>Fortunately there is a way that you can use a server sided scripting language like PHP store CSS variables in a PHP file and have the server send back the results to the browser with the mime type text/css. As explained by Chris Coyier over at <a href="http://css-tricks.com/css-variables-with-php/">CSS-Tricks</a> you can use PHP to create a CSS file. We&#8217;re going to take this a step further and create a theme switcher using the techniques used by Chris.</p>
<p>First of all we want to create a PHP file for the content of our page.  We will keep this pretty simple for the example but there is no reason why you couldn&#8217;t implement this into a site with far content and complex styles. Here is a simple starter page structure. Notice that the link to the CSS file is actually a PHP file located within a folder named css.</p>
<pre><code>
&lt;! DOCTYPE HTML &gt;
&lt; html &gt;
&lt;head&gt;
&lt;title&gt;PHP Variables In CSS Demo&lt;/title&gt;
&lt; meta http -equiv="Content -Type" content="text /html; charset = utf-8" /&gt;
&lt;link rel="stylesheet" href="css/style.php" type="text/css" media="screen" /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="wrap"&gt;
&lt;div id="nav"&gt;
&lt;img src="images/adamoliver.jpg" alt="adamoliver.net" id="logo" /&gt;
&lt;p id="switcher"&gt;
&lt;span&gt;switch theme:&lt;/span&gt;
&lt;a href="#"&gt;1&lt;/a&gt;
&lt;a href="#"&gt;2&lt;/a&gt;
&lt;a href="#"&gt;3&lt;/a&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;div id="header"&gt;
&lt;h1&gt;PHP Variables In PHP&lt;/h1&gt;
&lt;/div&gt;
&lt;div id="col1"&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;
&lt;/div&gt;
&lt;div id="col2"&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/ html &gt;
</code></pre>
<p>I&#8217;ve created some content with some navigation that will let us change the template used, a header that we will change the style of and two columns of text.</p>
<p>We&#8217;re going to use the querystring to allow us to change the current theme that is used by passing the name value pairs to the same PHP file. We will also want to remember which theme is currently being used so that if you wanted to the theme could be used throughout the rest of the site.</p>
<p>Insert the following PHP code before the doctype declaration:</p>
<pre><code>
&lt;?php
<span> </span>session_start();
<span> </span>
<span> </span>if (isset($_GET['template'])) {
<span> </span>$_SESSION['template'] = $_GET['template'];
<span> </span>$template = '?template='.$_SESSION['template'];
<span> </span>} elseif (isset($_SESSION['template'])) {
<span> </span>$template = '?template='.$_SESSION['template'];
<span> </span>} else {
<span> </span>$template = '';
<span> </span>}
?&gt;
</code></pre>
<p>Ok, so here is what that code actually does. Since we are using sessions we first need to start the session. Then we check to see if the querystring contains a value for the variable template. If it does then we assign the session variable template to it&#8217;s value. We then create a local variable contatining the string that we will append to the location of the CSS file. This string is a querystring with one name value pair. It will allow us to pass the name of the template we want to use to the PHP file creating the CSS styles. If the querystring does not exist for the page then a template hasn&#8217;t been requested. If there is a session we want to pass that value to the PHP file creating the CSS file, otherwise we will just leave the querystring passed to the PHP file creating the CSS blank and the default theme will be used.</p>
<p>Now that we know how we are going to handle requests for the different templates we can change the values of the links to update the template used - AKA the theme switcher. Update the links to include the querystring name of template with the value set to the name of your template.  In this case I&#8217;ve just used the numbers 1, 2 and 3.</p>
<pre><code>
&lt;p id="switcher"&gt;
<span> </span>&lt;span&gt;switch theme:&lt;/span&gt;
<span> </span>&lt;a href="index.php?template=1"&gt;1&lt;/a&gt;
<span> </span>&lt;a href="index.php?template=2"&gt;2&lt;/a&gt;
<span> </span>&lt;a href="index.php?template=3"&gt;3&lt;/a&gt;
<span> </span>&lt;/p&gt;
</code></pre>
<p>We also need to update the location of the PHP file creating the CSS. Just append the local variable containing the querystring values:</p>
<pre><code>
&lt;link rel="stylesheet" href="css/style.php&lt;?php echo $template; ?&gt;" type="text/css" media="screen" /&gt;</code></pre>
<p>Now we are ready to create our PHP file that will handle the creation of our template.  There is only line of code that will allow us to do this.  We just need to let our server know that we should send this PHP file as the content type of text/css.  Do this by including the following on the first line of the style.php file:</p>
<pre><code>
header("Content-type: text/css; charset: UTF-8");
</code></pre>
<p>Now you can simply use this file as you would do a normal CSS file but with the added benefit of parsing some PHP within it too. This can open up a whole host of options to allow you not only to dynamically change content on the page but also dynamically change the visual appearance of the page.</p>
<p>How I intend to use this is to firstly find out which template we should use.  Remember we can receive this information from the querystring.  Since I will be expecting a number of the value between 1 and 3 I will do some error checking first to see that the value sent is only one of those values.  Otherwise I will apply the default theme - theme number 1.</p>
<pre><code>
$numberoftemplates = 3;
if (isset($_GET['template'])) {
<span> </span>$template = $_GET['template'];
<span> </span>if ((!is_numeric($template)) || ($template &gt; $numberoftemplates) || ($template &lt; 0)) {
<span> </span>$template = 1;
<span> </span>} else {
<span> </span>$template = round($template);
<span> </span>}
} else {
<span> </span>$template = 1;
}</code></pre>
<p>Now I have a local variable named $template that holds the number of template I should be using.  For clarity I will echo this out using PHP:</p>
<pre><code>
echo '/*====== template used: '.$template.' ======*/';
</code></pre>
<p>Visit the style.php page now in the browser and &#8220;/*====== template used: 1 ======*/&#8221; should be shown.  If you change the querystring to style.php?template=2 then the template number 2 will be used.</p>
<p>Since we are not creating entire new CSS files for the different themes we are just going to define some differences between the themes and the main template.  We can store these differences into an array like so:</p>
<pre><code>
$css = array(
<span> </span>'header-background' <span> </span>=&gt; array(
<span> </span>1 =&gt; 'url(../images/header-bg-1.jpg) no-repeat',
<span> </span>2 =&gt; 'url(../images/header-bg-2.jpg) no-repeat',
<span> </span>3 =&gt; 'url(../images/header-bg-3.jpg) no-repeat'
<span> </span>),
<span> </span>'header-h1-colour'<span> </span>=&gt; array(
<span> </span>1 =&gt; '#fff',
<span> </span>2 =&gt; '#fff',
<span> </span>3 =&gt; '#666'
<span> </span>),
<span> </span>'header-h1-font'<span> </span>=&gt; array(
<span> </span>1 =&gt; 'bold normal 35px Helvetica, Arial, sans-serif',
<span> </span>2 =&gt; 'bold normal 35px Trebuchet MS, Arial, sans-serif',
<span> </span>3 =&gt; 'normal normal 35px Georgia, serif'
<span> </span>)
<span> </span>);
</code></pre>
<p>As you can see, I have defined three elements in the array for each CSS selector I want to change.  I have also defined an array as the value for each element in the array allowing me to give each selector a choice of three options depending on which theme we are using.</p>
<p>As an example all we need to do now is echo out the value from the array for our chosen theme into the CSS:</p>
<pre><code>
background: &lt;?php echo $css['header-background'][$template]; ?&gt;;
</code></pre>
<p>And that&#8217;s all that is required.  Use this throughout your file to allow you to change lots of visual elements of your site. The full styles I have used are shown below:</p>
<pre><code>
* {
margin:0;
padding:0;
}
body {
font-size:.8em;
background:#F3F4F9;
font-family:Arial;
text-align:center;
}
#wrap {
width:990px;
margin:0 auto;
text-align:left;
}
#nav {
padding:10px 0;
width:990px;
overflow:auto;
}
#logo {
float:left;
}
#switcher {
float:right;
width:170px;
text-align:right;
padding:45px 20px 0 0;
}
#switcher span {
float:left;
padding:6px 10px 0 0;
}
#switcher a {
display:block;
float:left;
padding:4px 8px;
border:1px solid #ccc;
background:#eee;
margin:0 0 0 2px;
}
#switcher a:hover {
background:#fff;
}
#header {
clear:both;
background: &lt;?php echo $css['header-background'][$template]; ?&gt;;
height: 206px;
}
#header h1 {
text-align:right;
padding:155px 25px 0 0;
color: &lt;?php echo $css['header-h1-colour'][$template]; ?&gt;;
font:&lt;?php echo $css['header-h1-font'][$template]; ?&gt;;
}
#col1 {
width:450px;
float:left;
margin:20px 0 0 0;
}
#col2 {
width:450px;
float:right;
margin:20px 0 0 0;
}
</code></pre>
<p><a class="srcfilesdownload" href="http://adamoliver.net/demos/php-variables-in-css/php-variables-in-css.zip">Download Theme Switcher With PHP Variables In CSS</a></p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/LiNmMowIPeg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/tutorials/theme-switcher-with-php-variables-in-css/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/tutorials/theme-switcher-with-php-variables-in-css/</feedburner:origLink></item>
		<item>
		<title>JSON: A Real World Example: Fill A Drop Down List</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/OLjqAwHRY2I/</link>
		<comments>http://blog.adamoliver.net/javascript/json-a-real-world-example-fill-a-drop-down-list/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 18:00:21 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
		
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=595</guid>
		<description><![CDATA[Find out how to use JSON, jQuery and PHP to fill a second option list with based on the value of the first one.]]></description>
			<content:encoded><![CDATA[<p>In my previous article on a <a href="http://blog.adamoliver.net/tutorials/a-simple-introduction-to-json-with-jquery-and-php/">simple introduction to JSON</a> I showed how to use JSON to post back to the server, do some calculations and respond with the results rendered in the browser.  In this example I will show you a real world example where you can select from a first option list and dynamically populate a second drop down list with items.</p>
<p><span id="more-595"></span></p>
<div class="downloadpanel clearfix">
<div class="left">
<h3>Requirements</h3>
<ul>
<li>A basic knowledge of HTML and PHP</li>
<li>Basic knowledge of jQuery assumed</li>
</ul>
</div>
<div class="left">
<h3>Demo</h3>
<ul>
<li><a href="http://adamoliver.net/demos/json-drop-down-list/">view demo</a></li>
<li><a href="http://adamoliver.net/demos/json-drop-down-list/json-drop-down-list.zip">download demo</a></li>
</ul>
</div>
</div>
<p>To begin with download jQuery and start the basic html page with the page structure and a link to the jQuery library.  We will use the built in post method within jQuery to post to the server and retrieve the results given from the PHP script.</p>
<pre><code>&lt;!DOCTYPE html &gt;
&lt; html &gt;
&lt;head&gt;
&lt;title&gt;JSON: A Real World Example&lt;/title&gt;
&lt;script src="jquery.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;/body&gt;
&lt;/ html &gt;</code></pre>
<p>Now on our page we are going to have two drop down lists. The first will be our primary option list which will be pre-populated with values.  The second will not have any values to start with but will instead be populated via an AJAX request depending on which option is selected in the primary option list.</p>
<p>Put the following drop down lists into the body section of the page:</p>
<pre><code>
&lt;select name="primary_select" id="primary_select"&gt;
<span> </span>&lt;option value="0"&gt;select an option&lt;/option&gt;
<span> </span>&lt;option value="1"&gt;option one&lt;/option&gt;
<span> </span>&lt;option value="2"&gt;option two&lt;/option&gt;
<span> </span>&lt;option value="3"&gt;option three&lt;/option&gt;
&lt;/select&gt;

&lt;select name="secondary_select" id="secondary_select"&gt;
&lt;/select&gt;
</code></pre>
<p>Before we code any javascript or PHP we should really hide the secondary options list from the user before they select from the first list. Add this line of CSS to hide the secondary drop down list:</p>
<pre><code>
&lt;style type="text/css"&gt;
#secondary_select {display: none;}
&lt;/style&gt;
</code></pre>
<p>Ok, now we are ready for some jQuery. We&#8217;ll start by capturing the change event of the primary option list. Every time a user selects a different option from the list the code will execute.  Within this code block we want to post the value of the selected option in the primary option list.  we can get this value using the val property of the option list as shown below:</p>
<pre><code>
&lt;script type="text/javascript"&gt;
<span> </span>$("#primary_select").change(function () {
<span> </span> <span> </span>
<span> </span> <span> </span>$.post("dynamicselect.php",
<span> </span> <span> </span>{
<span> </span> <span>     </span>primary_select : $('#primary_select').val(),
<span> </span> <span> </span>},
<span> </span>
<span>   </span>function(data){
<span> </span>
<span>   </span>}, "json");
});
&lt;/script&gt;
</code></pre>
<p>We&#8217;ve posted our selected value to the PHP script named dynamicselect.php and have set up the second argument of the post method ready to capture the response from the PHP script. We&#8217;ll come back to the results and how to populate the second list shortly.  Let&#8217;s first get into some PHP.</p>
<p>In one go here is all the PHP code we need:</p>
<pre><code>
$selected_option = $_POST['primary_select'];
<span> </span>
if ($selected_option == 0) {
    $options = '';
} elseif ($selected_option == 1) {
$options = array(
    'option one a'  =&gt; 'option one a',
    'option one b'  =&gt; 'option one b',
    'option one c'  =&gt; 'option one c',
    'option one d'  =&gt; 'option one d',
);
} elseif ($selected_option == 2) {
$options = array(
    'option two a'  =&gt; 'option two a',
    'option two b'  =&gt; 'option two b',
    'option two c'  =&gt; 'option two c',
    'option two d'  =&gt; 'option two d',
);
} elseif ($selected_option == 3) {
<span> </span>$options = array(
    'option three a'  =&gt; 'option three a',
    'option three b'  =&gt; 'option three b',
    'option three c'  =&gt; 'option three c',
    'option three d'  =&gt; 'option three d',
);
}

$array = array('options' =&gt; $options);
echo json_encode($options);
</code></pre>
<p>Here&#8217;s an explanation of what I did in the PHP code.  We can capture the value of the selected item in the primary drop down list and assign it to a local variable using this line:</p>
<pre><code>
$selected_option = $_POST['primary_select'];
</code></pre>
<p>The next section of code checks to see if the selected item&#8217;s value is equal to 0, 1, 2 or 3.  Depending on the results it assigns another variable, $options, with an array.  This array is a two dimensional array that we will send back to our page and assign the name and value pairs to the secondary drop down list.  In this case I have simply hard coded in some values but this script could easily be amended to fetch results from a database XML file or elsewhere to assign values to the array.</p>
<p>In the last two lines we create a new array to hold the current array, encode the array with the json_encode function and print the results to the page. This is then retrieved in the browser via javascript.</p>
<pre><code>$array = array('options' =&gt; $options);
echo json_encode($options);
</code></pre>
<p>Back in our javascript the our function is waiting for the results:</p>
<pre><code>
function(data){
<span> </span>$('#secondary_select').show();
<span> </span>$('#secondary_select').empty();
<span> </span>$.each(data, function(val, text) {
<span> </span> $('#secondary_select').append(
<span> </span> $('&lt;option&gt;&lt;/option&gt;').val(val).html(text)
<span> </span> );
<span> </span>});
</code></pre>
<p>Since we made our second drop down list invisible we&#8217;ll first use jQuery to show the option list on the page.</p>
<pre><code>
$('#secondary_select').show();
</code></pre>
<p>Each time this code runs it will append options to the select element.  So that we don&#8217;t just add to what is already there we want to first of all empty all contents of the select element.</p>
<pre><code>
$('#secondary_select').empty();
</code></pre>
<p>Then using jQuery we can loop through our array that we sent from PHP appending an option each time we run through the loop.</p>
<pre><code>
<span> </span>$.each(data, function(val, text) {
<span> </span> $('#secondary_select').append(
<span> </span> $('&lt;option&gt;&lt;/option&gt;').val(val).html(text)
<span> </span> );
</code></pre>
<p>And that&#8217;s it! When a user chooses from the first option list the second option list is displayed on the page and values are dynamically added to the list from values defined in the PHP script.  The full javascript code is shown below:</p>
<pre><code>
$("#primary_select").change(function () {
<span> </span>
<span>     </span>$.post("dynamicselect.php",
<span>     </span>{
<span>         </span>primary_select : $('#primary_select').val(),
<span>     </span>},
<span> </span>
<span>     </span>function(data){
<span>         </span>$('#secondary_select').show();
<span>         </span>$('#secondary_select').empty();
<span>         </span>$.each(data, function(val, text) {
<span> </span>            $('#secondary_select').append(
<span> </span>            $('&lt;option&gt;&lt;/option&gt;').val(val).html(text)
<span> </span>        );
<span>     </span>});</code></pre>
<pre><code><span>     </span>}, "json");
<span> </span>
});
</code></pre>
<p><a class="srcfilesdownload" href="http://adamoliver.net/demos/json-drop-down-list/json-drop-down-list.zip">Download JSON Drop Down List Files</a></p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/OLjqAwHRY2I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/javascript/json-a-real-world-example-fill-a-drop-down-list/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/javascript/json-a-real-world-example-fill-a-drop-down-list/</feedburner:origLink></item>
		<item>
		<title>A Simple Introduction To JSON with jQuery and PHP</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/WMTbZ4KP5HA/</link>
		<comments>http://blog.adamoliver.net/tutorials/a-simple-introduction-to-json-with-jquery-and-php/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 18:00:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=549</guid>
		<description><![CDATA[Using the jQuery we can easily load results via AJAX with only a few lines of javascript.]]></description>
			<content:encoded><![CDATA[<p>Before javascript libraries like jQuery came along asynchronously updating content with AJAX involved writing code which would account for the different ways that browsers posted back to the server with HTTP. Using the jQuery method post, we can easily load results via an HTTP post request with only a few lines of javascript.<br />
<span id="more-549"></span></p>
<div class="downloadpanel clearfix">
<div class="left">
<h3>Requirements</h3>
<ul>
<li>A basic knowledge of HTML and PHP</li>
<li>Basic knowledge of jQuery assumed</li>
</ul>
</div>
<div class="left">
<h3>Demo</h3>
<ul>
<li><a href="http://adamoliver.net/demos/json-simple-demo/">view demo</a></li>
<li><a href="http://blog.adamoliver.net/wp-content/uploads/2010/01/json-simple-demo.zip">download demo</a></li>
</ul>
</div>
</div>
<p>In this tutorial I will show you how to do this using a form to post a number to a PHP script which will do a simple calculation and return the results to the browser without a page refresh. In the next example coming up I will show you a more real world example of how this can be useful.</p>
<p>Start off with the basic HTML page structure and add the link to the jQuery library available from <a href="http://www.jquery.com">jquery.com</a>.</p>
<pre><code>
&lt;!DOCTYPE html &gt;
&lt; html &gt;
&lt;head&gt;
&lt;title&gt;JSON&lt;/title&gt;
&lt;script src="jquery.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;/body&gt;
&lt;/ html &gt;
</code></pre>
<p>In the body of the document we are going to use an input field to take a number from the user, a submit button to post the value to the PHP script an empty paragraph tag with the id of result as a placeholder for the result that will come from the PHP script.</p>
<pre><code>
&lt;h1&gt;JSON Example.&lt;/h1&gt;
&lt;p&gt;Enter a number to be multiplied by 4.&lt;/p&gt;
&lt;input id="textbox" name="textbox"&gt;&lt;/input&gt; x 4
&lt;input type="submit" name="submit" id="submit" value="calculate"&gt;&lt;/input&gt;
&lt;p id="result"&gt;&lt;/p&gt;
</code></pre>
<p>Now for some javascript. We&#8217;ll start off by capturing the click event of the submit button which we gave the id of submit. Using return false we can prevent the default action of the button - submitting the form - as we do not want the entire page to post back to the server.</p>
<pre><code>
&lt;script type="text/javascript"&gt;
$(document).ready(function(){
$("#submit").click(function () {

return false;
});
});
&lt;/script&gt;
</code></pre>
<p>Next we will add in the post jQuery post method which will allow us to post an array of values to the PHP script on the server using HTTP POST.</p>
<pre><code>
$.post("results.php",
{
theValue : $('#textbox').val(),
},
function(data){
$("#result").html(data.result);
}, "json");
</code></pre>
<p>Here we are posting the varible theValue with the value of what is entered by the user in the textbox with the id textbox to the php file results which will handle the processing of the data.</p>
<p>We will be working with this value on the server. The second argument that the post method requires is what is a function containing the results of what is returned from the server. As I will show shortly we will return a multidimensional array which will contain a value for result.  In this line of javascript:</p>
<pre><code>
$("#result").html(data.result);
</code></pre>
<p>I am taking the value as returned from the PHP script and replacing the contents of the paragraph tag we created with the id of result.</p>
<p>So with the values passed over to the PHP file we can now retrieve the values, do the required processing and return the results. The following code is placed into the results.php file.</p>
<pre><code>
&lt;?php
$theValue = $_POST['theValue'];

if (is_numeric($theValue)) {
$result = $theValue * 4;
} else {
$result = $theValue . ' is not a number.';
}

$data = array('result' =&gt; $result);
echo json_encode($data);
?&gt;
</code></pre>
<p>Firstly, we can retrieve the value of what was passed through the post method by using the $_POST function. Next I have done some simple error checking to see that what is entered is a number, if it is then the number is multiplied by four, if not then the result variable is assigned a value of an error message.</p>
<p>We then create an array of the results and use the json_encode function to encode the results into a json friendly syntax. Echo the $data array in this format and the results are received by the jQuery post function to display in the page.</p>
<p><a class="srcfilesdownload" href="http://blog.adamoliver.net/wp-content/uploads/2010/01/json-simple-demo.zip">Download JSON Simple Demo</a></p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/WMTbZ4KP5HA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/tutorials/a-simple-introduction-to-json-with-jquery-and-php/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/tutorials/a-simple-introduction-to-json-with-jquery-and-php/</feedburner:origLink></item>
		<item>
		<title>2010 - Time for resolutions</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/dbqla_GmWC4/</link>
		<comments>http://blog.adamoliver.net/personal/2010-time-for-resolutions/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 21:55:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=575</guid>
		<description><![CDATA[As it's the new year I have decided this year to push myself to achieve goals set out.]]></description>
			<content:encoded><![CDATA[<p>As it&#8217;s the new year I have decided this year to push myself to achieve goals set out. Some may call these resolutions. I prefer to think of them as long time goals as resolutions just don&#8217;t seem to work with me.  <span id="more-575"></span></p>
<p>I thought Jack Osborne wrote a good post on <a href="http://jackosborne.co.uk/articles/resolutions-for-2010/">his resolutions</a> for the new year and adding it to my blog where it is written down for me to check and update in a year&#8217;s time sounded like a good idea.</p>
<h4>Project 52</h4>
<p>Over the last few years posting to my blog has been patchy with rushes of inspiration coming now and again throughout the year but I would like to be more focused on this throughout the year and have decided to try to post to my blog once every week.  <a href="http://project52.info/">Project 52</a> kicked this idea off a few years ago.  Let&#8217;s see how long it lasts on my blog&#8230;</p>
<h4>Learn Japanese</h4>
<p>Ok, I&#8217;m unlikely to be a master of Japanese in a year but I aim to learn a lot more than I have done in the last couple of years.  I started listening to the podcasts over at <a href="http://www.japanesepod101.com">japanesepod101.com</a> a couple of years ago but never really got beyond the basics.  This year I hope to progress further with the aim of learning enough for a visit to Japan in 2011.</p>
<h4>Play and learn more guitar</h4>
<p>I have a million and one ideas for song writing but unfortunately over the last few years I have not practiced guitar as often as I would have liked.  Hopefully this year I can make some more time for practicing and writing some music. I can&#8217;t really see myself on Top of the Pops or whatever the equivalent is these days but maybe by the end of the year I might just have something recorded!</p>
<h4>Web Development - Continue to learn by doing</h4>
<p>Over the last few months I have pushed myself to learn more jQuery, PHP, AJAX, CSS3 and HTML5. With upcoming projects I hope to be able to use these newly learned skills and hope to set up some more websites that are community driven. I have a few ideas that I am keen to get going with already. Watch this space!</p>
<h4>Attend web conferences and meetups</h4>
<p>Working for a small company I sometimes feel that I miss out on the interaction with other people in the industry.  Attending the FOWD conference in 2009 was a great way to meet up with like-minded designers and developers.  I hope to go to more conferences this year as well as meeting new people at web design meet ups locally.</p>
<h4>Watch the IMDB top 100 films</h4>
<p>I recently had a look through the <a href="http://www.imdb.com/chart/top">top 100 films</a> on IMDB and realised there are a lot of them I have never seen and some I haven&#8217;t seen for ages.  I thought it would be a nice goal to aim to see all 100 of them this year!</p>
<p>Phew! Six things to achieve in a year! Maybe I&#8217;ll write a post in 6 months time with an update. What are you&#8217;re resolutions/goals for the new year? Post a note in the comments to let me know.</p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/dbqla_GmWC4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/personal/2010-time-for-resolutions/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/personal/2010-time-for-resolutions/</feedburner:origLink></item>
		<item>
		<title>View more or less content with jQuery</title>
		<link>http://feedproxy.google.com/~r/AdamOliversBlog/~3/oaWeBsjSLzE/</link>
		<comments>http://blog.adamoliver.net/jquery/view-more-or-less-content-with-jquery/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 15:38:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Tutorials]]></category>

		<category><![CDATA[jQuery]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://blog.adamoliver.net/?p=527</guid>
		<description><![CDATA[Learn how to use jQuery to unobtrusively view and hide more content in your page.]]></description>
			<content:encoded><![CDATA[<p>jQuery can be easily used to manipulate the way that content is displayed on a page.  Using unobtrusive javascript we can easily enhance a users experience if they have javascript enabled by allowing users to click to view more content.</p>
<p><span id="more-527"></span></p>
<div class="downloadpanel clearfix">
<div class="left">
<h3>Requirements</h3>
<ul>
<li>A basic knowledge of HTML and CSS</li>
<li>Basic knowledge of jQuery assumed</li>
</ul>
</div>
<div class="left">
<h3>Demo</h3>
<ul>
<li><a href="http://adamoliver.net/demos/more-less-jquery/">view demo</a></li>
<li><a href="http://blog.adamoliver.net/wp-content/uploads/2009/08/more-less-jquery.zip">download demo</a></li>
</ul>
</div>
</div>
<p>Since users of a website will only scan through the content in a page jQuery can easily be used to allow users to only view an introduction or summary of an article and then click to instantly view more.  In this tutorial I will show you how to use jQuery to hide a portion of the content at first and view the content when a user clicks a view more link.  Furthermore, I will show you how to change the link so that you can collapse the content again allowing the page to return to it&#8217;s original state.</p>
<p>Let&#8217;s start off with some simple HTML to get the page content in.  We will start by linking the jQuery library to the page, inserting an introduction in the body that users will see first, follow this with the content that users will see when they click to see more and finally the link that will allow users to view more or less content.  The order of this content is important as we will find out later.</p>
<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;View or Less Content With jQuery&lt;/title&gt;

&lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

          &lt;div class="intro"&gt;
          	&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.&lt;/p&gt;
          &lt;/div&gt;

          &lt;div class="moretext"&gt;
		&lt;p&gt;Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;
		&lt;p&gt;Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?&lt;/p&gt;
          &lt;/div&gt;

          &lt;p class="morelesslink more"&gt;view more&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;

</code></pre>
<p>Notice the class names I have given the content.  The intro is in a div with class name intro.  This class name isn&#8217;t actually used but could easily be to style differently from the rest of the content.  The following div is the content that we will be hiding to start with then showing when the link it clicked.  The final part is a paragraph of text which when clicked will show or hide out further content.</p>
<p>Ok, let&#8217;s get some functionality in there.  Our javascript is as follows:</p>
<p> </p>
<pre><code>&lt;script type = "text/javascript"&gt;
$(document).ready(function() {

 //hide the all of the elements with class moretext
$(".moretext").hide();      

//show the more link for users with javascript enabled
$(".morelesslink").show();      

//toggle the content to be displayed
$(".morelesslink").click(function()   {
if ($(this).prev(".moretext").is(":hidden"))
 {
$(this).html("view less");
$(this).prev(".moretext").slideToggle(600);
$(this).addClass("less");
$(this).removeClass("more");
} else {
$(this).html("view more");
$(this).prev(".moretext").slideToggle(600);
$(this).addClass("more");
$(this).removeClass("less");
}
});
});
&lt;/script&gt;

</code></pre>
<p>So what is this code doing? Let&#8217;s break it down. To start with we will take care of enhancing the page for browsers with javascript enabled and leave a usable page for those without.  The hidden text is hidden using jQuery and the link shown with jQuery so that all users without javascript will see the page with all content and no link to view more:</p>
<pre><code>(".moretext").hide();
$(".morelesslink").show();
</code></pre>
<p>Next we will create an event that handles the clicking of our link to view more or less content:</p>
<pre><code>$(".morelesslink").click(function()   {
});
</code></pre>
<p>Within this event we check to see if the more text is already hidden.  Since this event will handle both showing as well as hiding the text we need some logic to determine what state the page is in. The following if statement takes care of that:</p>
<pre><code>if ($(this).prev(".moretext").is(":hidden"))
 {
} else {
}
</code></pre>
<p>If the more text is hidden then we need to change the content to be shown, change the link&#8217;s text to &#8220;view less&#8221;, and we will also swap around some additional classes on the link for styling purposes.</p>
<p>We also want to do the opposite when the more text is visible and the link is clicked.  The link text will be changed to &#8220;view more&#8221;, the more text is toggled to hide the text using the slideToggle method in jQuery and again we swap about some classes for the link for styling.</p>
<p>Notice that to access the current more text for the specific link that we use the prev property.  This accesses the previous sibling in the HTML.  This is why it is important to keep the HTML in the same order as specified.</p>
<p>Here is the full if statement:</p>
<pre><code>if ($(this).prev(".moretext").is(":hidden"))
 {
$(this).html("view less");
$(this).prev(".moretext").slideToggle(600);
$(this).addClass("less");
$(this).removeClass("more");
} else {
$(this).html("view more");
$(this).prev(".moretext").slideToggle(600);
$(this).addClass("more");
$(this).removeClass("less");
}
</code></pre>
<p>Now all our javascript is up and running let&#8217;s tidy it up with a bit of CSS. We can now take advantage of the classes we added for the link: .more and .less.</p>
<p> </p>
<pre><code>

&lt;style type="text/css"&gt;
* {
margin:0;
padding:0;
}

body {
font-family:Arial;
font-size:.8em;
padding:1em;
}

p {
padding:.3em 0 .8em 0;
}

.morelesslink {
display:none;
background:#eee;
color:#333;
padding:.3em .6em .3em 2em;
border:1px solid #999;
cursor:pointer;
}

.more {
background:url(more.gif) no-repeat 5px center;
}

.less {
background:url(less.gif) no-repeat 5px center;
}

&lt;/style&gt;
</code></pre>
<p>And that&#8217;s it! Simple, reusable, progressively enhancing code. If you want to use the code more than once on the page you can do since it only requires the use of classes.  Just make sure that you keep the order of HTML the same.</p>
<p><a class="srcfilesdownload" href="http://blog.adamoliver.net/wp-content/uploads/2009/08/more-less-jquery.zip">Download jQuery more and less links</a></p>
<img src="http://feeds.feedburner.com/~r/AdamOliversBlog/~4/oaWeBsjSLzE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.adamoliver.net/jquery/view-more-or-less-content-with-jquery/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.adamoliver.net/jquery/view-more-or-less-content-with-jquery/</feedburner:origLink></item>
	</channel>
</rss>
