<?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>Scunby</title>
	<atom:link href="http://www.scunby.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scunby.com</link>
	<description>Web Design From Manchester</description>
	<lastBuildDate>Fri, 25 Jun 2010 10:11:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>PHP Classes: An Introduction to OOP</title>
		<link>http://www.scunby.com/php-classes-an-introduction-to-oop/</link>
		<comments>http://www.scunby.com/php-classes-an-introduction-to-oop/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 13:51:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=187</guid>
		<description><![CDATA[There is still much debate about Object Orientated Programming (OOP) with PHP, largely because PHP wasn&#8217;t developed as an OOP language, and it works perfectly well as a procedural language for most web applications or websites that you are creating. On top of that, on face value, OOP can seem daunting and overly-elaborate, with many [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_188" class="wp-caption alignnone" style="width: 650px"><a href="http://www.scunby.com/wp-content/uploads/2010/04/OOP-she-did-it-again.jpg"><img class="size-full wp-image-188 " title="OOP she did it again" src="http://www.scunby.com/wp-content/uploads/2010/04/OOP-she-did-it-again.jpg" alt="OOP she did it again" width="640" height="350" /></a><p class="wp-caption-text">OOP: she did it again</p></div>
<p>There is still much debate about Object Orientated Programming (OOP) with PHP, largely because PHP wasn&#8217;t developed as an OOP language, and it works perfectly well as a procedural language for most web applications or websites that you are creating. On top of that, on face value, OOP can seem daunting and overly-elaborate, with many more lines of code needed to achieve something simple, compared to the procedural way.</p>
<p>That said, OOP PHP can become really useful on a community level, because generic-purpose classes can be created with all sorts of uses, such as easily creating word documents, creating pdfs, flash interaction, image/audio manipulation, and, well, basically anything you could dream of.</p>
<p>To get a picture of the power of php classes, you could maybe take a moment to look around the aptly named <a href="http://www.phpclasses.org/browse/">www.phpclasses.org</a>, where anyone can use or contribute their own php classes with each other, creating a repository far more powerful than a single brain could muster.</p>
<p>So, it&#8217;s worth understanding the OOP principals and syntax within PHP, whether you want to start adhering to strict OOP protocols in the future, or if you simply want to understand the basics of OOP in order to be able to dabble into other people&#8217;s classes when it takes your fancy.</p>
<p>For this tutorial we&#8217;re going to introduce PHP classes, creating a simple class that prints out a reusable, customisable textbox for a website.</p>
<h3>The PHP Class</h3>
<p> The <strong>class</strong> is the crux of OOP, and in simple terms is a collection of variables and functions that are related to each other. Here is an example of a lovely PHP class:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> infobox <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$variable</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$another</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>And to access the data inside this class, you can use the following syntax:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$infobox</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> infobox<span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">variable</span><span style="color: #339933;">;</span> <br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">another</span><span style="color: #339933;">;</span></div></div>
<p>Here we create a new infobox instance, and then we can echo the variables inside it with the rather exciting &#8220;right arrow&#8221;, which will become your new OOP best friend. Of course, classes can become a lot more complex, and a lot more useful, but this principle, that the class is grouping two variables together in a family, is the basis for all OOP.</p>
<p>Now we are going to make a class that has a little more purpose. We want to make a class that will print out a textbox with a header and a body text, which has default colours that can be changed using functions.</p>
<p>First of all, we&#8217;ll set up some CSS, just to make things look pretty. Note that we&#8217;re not defining the infobox&#8217;s width or background colour, or the h2 element&#8217;s text colour. These will be defined by the PHP class.</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">body <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Arial</span><span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">letter-spacing</span><span style="color: #00AA00;">:</span><span style="color: #933;">-1px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #6666ff;">.infobox</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* For Firefox */</span><br />
&nbsp; &nbsp; -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* For Safari &amp; Chrome */</span><br />
&nbsp; &nbsp; -khtml-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* KHTML */</span><br />
&nbsp; &nbsp; border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* CSS3 */</span><br />
<span style="color: #00AA00;">&#125;</span><br />
p <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<p>Now that this is out the way, we can create a class. The variables of this class will define what can be customised by the user, in this instance, the width of the infobox, the background colour, and the text colour of the infobox&#8217;s heading.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> infobox <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$bgcolour</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;c3ffc4&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$h2colour</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;71a873&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Now we need to create a function within this class that will print out an infobox every time it is invoked. Let&#8217;s have a look at that:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> infobox <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$bgcolour</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;c3ffc4&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$h2colour</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;71a873&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> output<span style="color: #009900;">&#40;</span><span style="color: #000088;">$heading</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div class=&quot;infobox&quot; style=&quot;background:#'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bgcolour</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'; width:'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">width</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'px;&quot;&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$p</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;h2 style=&quot;color:#'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">h2colour</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">';&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$heading</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$p</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;p&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$body</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$p</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$p</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>We are greeted with a new syntax here, &#8220;$this->variable.&#8221; When operating functions within a class, you can access all the variables that belong to the class with this syntax. So here we use &#8220;$this->colour&#8221;, to access the variable $colour from the top of the class.</p>
<p>The function <strong>output()</strong> simply creates an echoed string that contains a div, an h2 tag and a p tag. The tags contain some user defined variables. It also sets the colours and width of the infobox using the default, set variables of the class. Let&#8217;s see how we can use this.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$infobox</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> infobox<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Title for the Box'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Some body text for the box'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Here, we create a new instance of the class, $infobox, and we access the function<strong> output() </strong> in the same manner as we access the variables of the class, with a right arrow. We pass two variables into the function, one for the title, one for the body, and we end up with an output like this:</p>
<p><a href="http://www.scunby.com/wp-content/uploads/2010/04/textbox.png"><img src="http://www.scunby.com/wp-content/uploads/2010/04/textbox.png" alt="" title="textbox" width="640" height="193" class="alignnone size-full wp-image-190" /></a></p>
<p>Now, what if we want to change the default variables within this class? We can create some new functions that will make this happen.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> changeWidth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newWidth</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newWidth</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>If we put this into our class, we have a new function to access, that will set the $width variable of the class to our new variable. So we could run:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$infobox</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> infobox<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">changeWidth</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Title for the Box'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Some body text for the box'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>And now, instead of having the default 300 pixels wide infobox, we have an infobox that is 500 pixels wide. We can create similar functions to alter the background and text colours, and end up with a class like this:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> infobox <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$bgcolour</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;c3ffc4&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$h2colour</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;71a873&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> output<span style="color: #009900;">&#40;</span><span style="color: #000088;">$heading</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div class=&quot;infobox&quot; style=&quot;background:#'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bgcolour</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'; width:'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">width</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'px;&quot;&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$p</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;h2 style=&quot;color:#'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">h2colour</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">';&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$heading</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$p</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;p&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$body</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$p</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$p</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> changeWidth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newWidth</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newWidth</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> changeBgColour<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newColour</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bgcolour</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newColour</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> changeh2Colour<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newColour</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">h2colour</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newColour</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Now we have a class with default settings, and the ability to change all three settings with a function, and then a main function for outputting the data, so whenever an infobox is needed to be echoed into your application you can make it happen from one class. Let&#8217;s give it a test run:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$infobox</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> infobox<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Title'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'This is some body text'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">changeWidth</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'New Title'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Some more body text for the second infobox'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">changeBgColour</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a4a4a4'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">changeh2Colour</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'000000'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$infobox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Third Title'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'More text for the final infobox, with different colours!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Here we output three infoboxes. The first has the default settings, the second has the width changed to 500, and the third has the colours changed to greys and blacks.</p>
<p><a href="http://www.scunby.com/wp-content/uploads/2010/04/webdesign-php-classes-example.jpg"><img src="http://www.scunby.com/wp-content/uploads/2010/04/webdesign-php-classes-example.jpg" alt="" title="webdesign-php-classes-example" width="640" height="336" class="alignnone size-full wp-image-191" /></a></p>
<p>And there we have it, your first introduction to php OOP, using the php class to create something practical for your site development. Of course this is very simple and doesn&#8217;t even start to touch on the complexity of classes and their power, but it does explain the benefits and theory behind the PHP class, and why it can be more useful than simple procedural methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/php-classes-an-introduction-to-oop/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rounded Corners with css3 and javascript</title>
		<link>http://www.scunby.com/rounded-corners-with-css3-and-javascript/</link>
		<comments>http://www.scunby.com/rounded-corners-with-css3-and-javascript/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 12:15:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=170</guid>
		<description><![CDATA[If there&#8217;s one thing that the internet has taught us in the twenty or so years it&#8217;s been alive, it&#8217;s that everybody loves rectangles with rounded edges. It all stems from the age old human condition that we need things in boxes- we need order and division, organisation and categorisation, but at the same time [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.scunby.com/wp-content/uploads/2010/04/curved-edges.png"><img class="alignnone size-full wp-image-178" title="Cross Browser Curved Edges" src="http://www.scunby.com/wp-content/uploads/2010/04/curved-edges.png" alt="Cross Browser Curved Edges" width="640" height="258" /></a></p>
<p>If there&#8217;s one thing that the internet has taught us in the twenty or so years it&#8217;s been alive, it&#8217;s that <strong>everybody loves rectangles with rounded edges</strong>. It all stems from the age old human condition that we need things in boxes- we need order and division, organisation and categorisation, but at the same time we&#8217;re not quite willing to accept our brains are like this. We want to pretend we can &#8220;think outside the box,&#8221; that we are maverick, free thinking non-comformists.</p>
<div id="attachment_183" class="wp-caption alignright" style="width: 180px"><a href="http://www.scunby.com/wp-content/uploads/2010/04/che-guevera-in-a-rounded-box.png"><img class="alignright size-full wp-image-183" title="Che Guevera in a rounded box" src="http://www.scunby.com/wp-content/uploads/2010/04/che-guevera-in-a-rounded-box.png" alt="Che Guevera in a rounded box" width="170" height="212" /></a><p class="wp-caption-text">Che Guevera in a rounded box. &quot;Look Mom, I am an individual!&quot;</p></div>
<p>We want to pretend we are not putting things in boxes, that we are doing things are own way. The rounded corner is a symbol of our imaginary human individualism, screaming to the world that we are <em>not</em> conforming, we haven&#8217;t been forced into <strong>the box</strong>. But, when all&#8217;s said and done, the box remains.</p>
<p>Erm, anyway, pop-psychology out of the way, rounded edges are so successful in web design because computers and design code mean we have to use a grid-based layout of some kind, with divs and spans all in rectangles, and all these boxes start to look tired and dull on the eye. Rounded edges are a nice, quick way to spruce up boxes whilst still being able to maintain the sensible, grid based structure such geometries require.</p>
<h2>How do we do it then?</h2>
<p>As with everything in web design, there are many ways to achieve your goal here. The old way was to use four corner divs for every box, and use a .png of each corner segment as a background image. I spent many hours in the olden days using this method, only for the client to say they want a different shade of blue for the boxes and I would have to crank up Photoshop and make some more.</p>
<p>Nowadays, with css3 becoming (almost) mainstream, life is simpler. The css mark-up is as so:</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.rounded</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* CSS3 */</span><br />
&nbsp; &nbsp; -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* For Older Firefox */</span><br />
&nbsp; &nbsp; -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* For Older Safari &amp; Chrome */</span><br />
&nbsp; &nbsp; -khtml-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* KHTML */</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<p>So, we see it&#8217;s not quite homogenised yet, and to be sure you&#8217;re better off putting all four of these lines into your css file. And even then, we have problems with Internet Explorer. My recommended solution for this is the awesome <strong>javascript</strong> creation <a title="Javascript CurvyCorners" href="http://www.curvycorners.net/downloads/">CurvyCorners.js</a>. This javascript file will auto-detect if the browser being used can deal with CSS3, and if it can&#8217;t it will invoke curved corners on all elements in your CSS file that have border-radius defined.</p>
<p>This is good news, because all you have to do is link the .js file in your header, and do nothing else.</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;path-to-my-javascript/curvycorners.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span></div></div>
<p>In this day and age we shouldn&#8217;t have to worry about rounded corners. If you keep this method in your head you won&#8217;t have to worry about it any more. Sooner or later the javascript won&#8217;t even be needed as all browsers will be CSS3 compatible, but until that day, use these two easy steps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/rounded-corners-with-css3-and-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>80 Hertz</title>
		<link>http://www.scunby.com/80-hertz/</link>
		<comments>http://www.scunby.com/80-hertz/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 15:50:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=76</guid>
		<description><![CDATA[80 Hertz recording studios is a high end Manchester &#8211; based music studio and they needed a site that reflected that. The site look and feels modern and unique, and is easy to update and maintain. The website is also built with SEO in mind, and has been targeted with specific Google keywords to increase [...]]]></description>
			<content:encoded><![CDATA[<p>80 Hertz <a title="recording studios" href="http://www.80hertz.com">recording studios</a> is a high end Manchester &#8211; based music studio and they needed a site that reflected that. The site look and feels modern and unique, and is easy to update and maintain. The website is also built with SEO in mind, and has been targeted with specific Google keywords to increase traffic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/80-hertz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beat Bazaar</title>
		<link>http://www.scunby.com/beat-bazaar/</link>
		<comments>http://www.scunby.com/beat-bazaar/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 15:36:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=71</guid>
		<description><![CDATA[Working closely with Bioport, a site was developed for Manchester Record Label Beat Bazaar. The website needed to be visually unique and fashionable looking, as well as easy to update and manage. The website contains music, videos, artist biographies and an online store for selling music and memorabilia.]]></description>
			<content:encoded><![CDATA[<p>Working closely with <a title="Bioport web design" href="http://www.bioport.cz/" target="_blank">Bioport</a>, a site was developed for Manchester Record Label Beat Bazaar. The website needed to be visually unique and fashionable looking, as well as easy to update and manage. The website contains music, videos, artist biographies and an online store for selling music and memorabilia.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/beat-bazaar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cats in Paris</title>
		<link>http://www.scunby.com/cats-in-paris/</link>
		<comments>http://www.scunby.com/cats-in-paris/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 15:26:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=68</guid>
		<description><![CDATA[To create a site for a band requires a back end that is strong and simple to use, so that updates can be achieved easily and with the minimum of fuss. A slick, cool look then needs to be achieved with the design, mirroring that of the band&#8217;s identity and album artwork. This site has [...]]]></description>
			<content:encoded><![CDATA[<p>To create a site for a band requires a back end that is strong and simple to use, so that updates can be achieved easily and with the minimum of fuss. A slick, cool look then needs to be achieved with the design, mirroring that of the band&#8217;s identity and album artwork. This site has a custom CMS and a facility for video and music uploads.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/cats-in-paris/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternate colours for list items from a php array</title>
		<link>http://www.scunby.com/alternate-colours-for-listed-items/</link>
		<comments>http://www.scunby.com/alternate-colours-for-listed-items/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 14:20:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=29</guid>
		<description><![CDATA[Very often we need to take data from an array and display it on a page. And how better to present this than with alternately coloured boxes? They can fit in with the style of your site, break up the data, and make readability that much better. Here we&#8217;ll take a look at the best [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.scunby.com/wp-content/uploads/2009/12/alt-divs.png"><img class="alignnone size-full wp-image-112" title="Alternative Coloured Lists" src="http://www.scunby.com/wp-content/uploads/2009/12/alt-divs.png" alt="Alternative Coloured Lists" width="640" height="300" /></a></p>
<p>Very often we need to take data from an array and display it on a page. And how better to present this than with alternately coloured boxes? They can fit in with the style of your site, break up the data, and make readability that much better. Here we&#8217;ll take a look at the best ways to make this happen.</p>
<p>First of all, we&#8217;ll style our unordered list with some css, and then create a class for the alternative colour. Here, the regular list item is a lovely shade of pink, and the alternative class is a rather fetching grey.</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">li <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Arial</span><span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">letter-spacing</span><span style="color: #00AA00;">:</span><span style="color: #933;">-1px</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#E39A9A</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">dashed</span> <span style="color: #cc00cc;">#999</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.alt</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<p>Next we need to write a loop in php that will take all items from a php array (here named rather aptly <strong>$array</strong>). There&#8217;s many ways to do this, but I&#8217;ll be using my favourite method, the <strong>foreach </strong>statement.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;ul&gt;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li class=&quot;alt&quot;&gt;'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;'</span> <span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$count</span> <span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;/ul&gt;</div></div>
<p>So what&#8217;s going on there? First of all, we need to set up a variable called <strong>$count</strong>, which will count how many times the loop has been made:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></div></div>
<p>As we&#8217;re putting this before any loops have been made, we set it at zero. This will be incremented every time the loop is passed. Then we need to wrap everything up in ul tags (for our unordered list), and then create a loop that takes each item from the array as a new variable, called <strong>$item</strong>. Let&#8217;s look at that:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>The <strong>foreach</strong> loop is expanding the array named <strong>$array</strong> and creating a variable called <strong>$item</strong>. Next, we create a conditional statement for inside the loop that will check if <strong>$count</strong> is currently an even number.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li class=&quot;alt&quot;&gt;'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;'</span> <span style="color: #339933;">;</span></div></div>
<p>This snippet checks to see if <strong>$count</strong> divides by two. If it does, we will echo a <strong>li</strong> with class &#8220;alt&#8221;. If it doesn&#8217;t divide by two, we will echo out a standard <strong>li</strong> tag. Next, we can echo the current array item, with the variable <strong>$item</strong>, and then close the <strong>li</strong> tag.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span></div></div>
<p>And finally, we need to add one to the variable <strong>$count</strong>, so that it doesn&#8217;t stay on 0.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$count</span><span style="color: #339933;">++;</span></div></div>
<p>This is a short way of writing &#8220;add one to the variable&#8221; and is very useful to remember for php development.</p>
<h3>Other methods</h3>
<p>Like almost all solutions in php, this is only one of many. There are hundreds of methods that all lead to the same conclusion, but it&#8217;s worthwhile picking one now, and sticking with it. It can save time and effort in the future if you have snippets saved up for general tasks like this, and if there is homogeneity amongst your application code it will be quicker to write and easier to edit in the future.<br />
Now then, it&#8217;s probably a good time to mention the shortest possible method out there for alternative colour rows in php:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;ul&gt;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span>?<span style="color: #0000ff;">' class=&quot;alt&quot;'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&gt;<span style="color: #006699; font-weight: bold;">$item</span>&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;/ul&gt;</div></div>
<p>The principle is exactly the same as our detailed method, but it has been shrunk down using shortcodes and concatenation. The <strong>$count</strong> variable has also been changed to a Boolean so that it can be flipped from true to false in less characters. If you know of a faster way, be sure to comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/alternate-colours-for-listed-items/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moon Restaurant</title>
		<link>http://www.scunby.com/moon-restaurant-web-design/</link>
		<comments>http://www.scunby.com/moon-restaurant-web-design/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 14:05:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=64</guid>
		<description><![CDATA[Created the website and menu design for Moon Restaurant, a modern Indian restaurant based in Manchester. The client asked for something that seems fashionable and slick, without forgetting the traditional roots of Indian cookery. What was created was a smart, sophisticated design that is both Search Engine Friendly and easy to update.]]></description>
			<content:encoded><![CDATA[<p>Created the website and menu design for Moon Restaurant, a modern Indian restaurant based in Manchester. The client asked for something that seems fashionable and slick, without forgetting the traditional roots of Indian cookery. What was created was a smart, sophisticated design that is both Search Engine Friendly and easy to update. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/moon-restaurant-web-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Relapse Media Ltd.</title>
		<link>http://www.scunby.com/relapse-media-ltd/</link>
		<comments>http://www.scunby.com/relapse-media-ltd/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 13:58:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=61</guid>
		<description><![CDATA[Designed and developed a website for a new music magazine based in Manchester. The site contains articles, music, video blogs and an online store, and is fully updated and managed by the client, with an easy to use content management system and layout.]]></description>
			<content:encoded><![CDATA[<p>Designed and developed a website for a new music magazine based in Manchester. The site contains articles, music, video blogs and an online store, and is fully updated and managed by the client, with an easy to use content management system and layout. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/relapse-media-ltd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving Domains with WordPress and phpMyAdmin</title>
		<link>http://www.scunby.com/moving-domains-with-wordpress-and-phpmyadmin/</link>
		<comments>http://www.scunby.com/moving-domains-with-wordpress-and-phpmyadmin/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 21:55:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=1</guid>
		<description><![CDATA[Moving your WordPress site from one domain to another can be a tricky affair if you aren&#8217;t overly familiar with MySQL and database handling. Here, I&#8217;ll go through a simple way to make it happen, by exporting and editing your MySQL data using phpmyadmin and a text editor. phpMyAdmin is usually provided by most hosting [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.scunby.com/wp-content/uploads/2009/12/phpmyadmin.jpg" alt="" title="phpmyadmin" width="640" height="274" class="alignnone size-full wp-image-147" /></p>
<p>Moving your WordPress site from one domain to another can be a tricky affair if you aren&#8217;t overly familiar with MySQL and database handling. Here, I&#8217;ll go through a simple way to make it happen, by exporting and editing your MySQL data using <a title="phpmyadmin" href="http://www.phpmyadmin.net/home_page/index.php">phpmyadmin</a> and a text editor. </p>
<p>phpMyAdmin is usually provided by most hosting companies and acts as a nice and easy way to access your MySQL data without having to actually code any, or get your hands dirty.</p>
<h3>Step One: Export Your Existing Database</h3>
<p><a href="http://www.scunby.com/wp-content/uploads/2009/12/export.png"><img src="http://www.scunby.com/wp-content/uploads/2009/12/export.png" alt="export database" title="export database" width="640" height="274" class="alignnone size-full wp-image-148" /></a></p>
<p>To get your database exported from your existing server or localhost and into a specific file on your computer, you must first log in to your phpMyAdmin area and select the <strong>export</strong> tab on your database. There&#8217;s a heap of options there, but don&#8217;t be daunted, as the defaults will be fine. Make sure, however, you check <strong>&#8220;Save as file&#8221;</strong>. This will save a file onto your computer containing every single bit of data from your WordPress database. Now you can make the necessary changes to the file.</p>
<h3>Step Two: Find/Replace All Occurrences of the Old Domain Name</h3>
<p>Open up the .sql file in any text editor. For this you can use Dreamweaver, Notepad, TextMate, Text Edit or anything at your disposal. The only thing to be wary of is that the file size on large sites will be large, heavy and cumbersome on some computers, because of the sheer amount of text involved. If your computer starts wheezing, try and bare with it!</p>
<p>Using the find/replace feature on your text editor, type in your old domain name, and in the &#8216;replace&#8217; section, put in your new domain name. It might take a little time to complete, depending on your computer, and it normally replaces a few hundred occurrences of your old domain name.</p>
<h3>Step Three: Find/Replace All Occurrences of the Absolute Path</h3>
<p>Next up is to change the Absolute Path of your WordPress site. This can be a bit baffling,  especially if you have no idea what an Absolute Path is. Just to clarify, your website&#8217;s Absolute Path is the place where all of its files live on the server it uses, and it tends to be needed by WordPress for the media gallery uploader and plugins that involve uploading files.</p>
<p>The easiest way to find out your absolute path is to create a php file and write:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>When you view this output in a browser, you will find the absolute path, which normally looks something like &#8220;/var/www/my-domain&#8221;.</p>
<p>Now that you have this new information, replace your current absolute path with your new absolute path in your .sql file. There should only be a few instances of this.</p>
<h3>Step Four: Importing the Adjusted Database</h3>
<p>Now that we&#8217;ve made the necessary changes you can save your .sql file and head to the phpmyadmin control panel on your new domain. Here, make sure you are working with an empty database, or add a new database, and then head to &#8216;<strong>import</strong>&#8216;. Pick the edited .sql file from your computer, and let it upload.</p>
<h3>Step Five: The End</h3>
<p>With the database set up and ready to rock, we can upload all of the files to the new domain, <strong>except for config.php</strong>. This is the file that tells WordPress how to connect to the database, and as we&#8217;ve changed servers the database details will not be correct. </p>
<p>Once everything is uploaded you can head to your-new-domain.com and, thanks to the lack of a config.php file, you will be greeted with a WordPress installation screen:</p>
<p><a href="http://www.scunby.com/wp-content/uploads/2009/12/no-config-file.png"><img src="http://www.scunby.com/wp-content/uploads/2009/12/no-config-file.png" alt="There apears to be no config file" title="no-config-file" width="640" height="202" class="alignnone size-full wp-image-150" /></a></p>
<p>Now you can follow the lovely WordPress instructions to put in your new database details, and a new config file will be created on your server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/moving-domains-with-wordpress-and-phpmyadmin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>White Noise Productions</title>
		<link>http://www.scunby.com/white-noise-productions/</link>
		<comments>http://www.scunby.com/white-noise-productions/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 23:29:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://www.scunby.com/?p=46</guid>
		<description><![CDATA[Designed and developed a dynamic and easy to update website for White Noise Productions, a TV production company based in Darwen, Lancashire. Working closely with the team at White Noise, a site was created that both sums up the identity of the company, has a simple to use CMS that is easy to update, and [...]]]></description>
			<content:encoded><![CDATA[<p>Designed and developed a dynamic and easy to update website for White Noise Productions, a TV production company based in Darwen, Lancashire. Working closely with the team at White Noise, a site was created that both sums up the identity of the company, has a simple to use CMS that is easy to update, and includes an in depth portfolio of commercials, built using Flash AS 3.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scunby.com/white-noise-productions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

