<?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>Online Source For HTML, XHTML, CSS, JavaScript, AJAX, XML, PHP, Ruby, PHP Frameworks &#187; PHP</title>
	<atom:link href="http://www.w3updates.com/category/server-scripting/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.w3updates.com</link>
	<description>html tutorials, html tips, PHP, SQL, MySql, MSSQL, PHP Tutorial,  html codes, XHTML, CSS, JS Tutorial,  Learn html,  Ruby on Rails, Ajax tutorial, PHP Frameworks Tutorial, ASP.NET, W3 School, W3 Validator, Flash Tutorial, SEO Tips, Web Building, Server Scripting</description>
	<lastBuildDate>Fri, 26 Mar 2010 01:33:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introduction to PHP – Part8</title>
		<link>http://www.w3updates.com/server-scripting/php/introduction-to-php-%e2%80%93-part8/</link>
		<comments>http://www.w3updates.com/server-scripting/php/introduction-to-php-%e2%80%93-part8/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 08:16:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.w3updates.com/?p=1312</guid>
		<description><![CDATA[Function:
A function is a subprogram that performs a specific task when called by the main program. It is always a good practice to divide a huge program into a number of subprograms until elementary functions are reached. More clearly, a huge program should be divided into number of functions, and a function precisely should do [...]]]></description>
			<content:encoded><![CDATA[<p>Function:<br />
A function is a subprogram that performs a specific task when called by the main program. It is always a good practice to divide a huge program into a number of subprograms until elementary functions are reached. More clearly, a huge program should be divided into number of functions, and a function precisely should do one job. Suppose, we have a big program that reads data from user at the beginning, save data to a database and displays the saved data at the end. We can divide this program into three subprograms or functions. The first function reads data from user, the second function writes data to the database and finally third function writes data to monitor.</p>
<p>There are number of advantages of implementing a huge program into a number of subprograms. The first advantage is we can reuse the existing code. During a single execution of a program, a function can be called several times from different places and even from another function. The second advantage is it is easy to understand the program logic, debugging and testing is easier.</p>
<p>Functions can be categorised in two broad topics, built-in functions and user defined functions. Built-in functions are the language constructs that comes with PHP. There are hundreds of built-in functions available in PHP for our use. User-defined functions are the functions created by programmers. In this tutorial we will discuss user-defined functions in detail.</p>
<p>Creating function</p>
<p>Let us start with a simple function that calculates sum of two numbers.</p>
<p>Example#1</p>
<p><html><br />
<body><br />
<?php<br />
/*<br />
This function calculates the sum of two numbers<br />
*/<br />
function sum()<br />
{<br />
            //declare and initialize variables<br />
            $x=20;<br />
            $y=30;<br />
            $z=$x+$y;<br />
            //print the result<br />
            echo 'The value of $x is '.$x. ' and value of $y is '. $y .' The result of  $x + $y is '.$z;<br />
}<br />
//Execution of this program starts from here, and calls the function sum, that means code inside the function sum will be executed<br />
sum();<br />
?><br />
</body></p>
<p>Function with parameter</p>
<p>Though we can call the function sum in example#1 as many times as we want, it produces the same result. Let us modify the above code to achieve better result.</p>
<p>Example#2</p>
<p><html><br />
<body><br />
<?php<br />
/*<br />
This function calculates the sum of two numbers<br />
*/<br />
function sum($x,$y)<br />
{<br />
            //Calculate result<br />
            $result=$x+$y;<br />
            //print the result<br />
            echo $result;<br />
}<br />
//Execution starts from here<br />
$x=20;<br />
$y=30;<br />
sum($x,$y);</p>
<p>//We can call the function using different value<br />
$x=200;<br />
$y=300;<br />
sum($x,$y);<br />
?><br />
</body><br />
The code in both examples provides the same functionality but the variables in example#1 are hardcoded inside the function itself and hence, can provide the functionality of adding the hardcoded values. If we have to add other numbers we have to write another function. The code in example#2 solves this problem by passing parameters and provides more functionality. We can add any two numbers any times by just calling the function with parameters. The function sum in example#2 takes two parameters. The parameters are enclosed in parenthesis and separated by comma.</p>
<p>Function with parameter and return value</p>
<p>A function can also return value. The return statement is optional. A function can return any type including arrays and objects. After a function returns a value, its execution is passed back to the line from which it was called. Let us modify the code of example#2 to see how a function can return value.</p>
<p>Example#3</p>
<p><html><br />
<body><br />
<?php<br />
/*<br />
This function calculates and returns the sum of two numbers<br />
*/<br />
function sum($x,$y)<br />
{<br />
            //Calculate result<br />
            $result=$x+$y;<br />
            return $result;<br />
}<br />
//Execution starts from here<br />
$x=200;<br />
$y=300;<br />
//calculate and print the result<br />
echo "The sum is : ". sum($x,$y);<br />
?><br />
</body><br />
For a complete reference of functions please visit http://www.php.net/manual/en/language.functions.php<br />
webanddesigners.com</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;bodytext=Function%3A%0D%0AA%20function%20is%20a%20subprogram%20that%20performs%20a%20specific%20task%20when%20called%20by%20the%20main%20program.%20It%20is%20always%20a%20good%20practice%20to%20divide%20a%20huge%20program%20into%20a%20number%20of%20subprograms%20until%20elementary%20functions%20are%20reached.%20More%20clearly%2C%20a%20huge%20progr" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;notes=Function%3A%0D%0AA%20function%20is%20a%20subprogram%20that%20performs%20a%20specific%20task%20when%20called%20by%20the%20main%20program.%20It%20is%20always%20a%20good%20practice%20to%20divide%20a%20huge%20program%20into%20a%20number%20of%20subprograms%20until%20elementary%20functions%20are%20reached.%20More%20clearly%2C%20a%20huge%20progr" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;t=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;annotation=Function%3A%0D%0AA%20function%20is%20a%20subprogram%20that%20performs%20a%20specific%20task%20when%20called%20by%20the%20main%20program.%20It%20is%20always%20a%20good%20practice%20to%20divide%20a%20huge%20program%20into%20a%20number%20of%20subprograms%20until%20elementary%20functions%20are%20reached.%20More%20clearly%2C%20a%20huge%20progr" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;headline=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=Function%3A%0D%0AA%20function%20is%20a%20subprogram%20that%20performs%20a%20specific%20task%20when%20called%20by%20the%20main%20program.%20It%20is%20always%20a%20good%20practice%20to%20divide%20a%20huge%20program%20into%20a%20number%20of%20subprograms%20until%20elementary%20functions%20are%20reached.%20More%20clearly%2C%20a%20huge%20progr" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;bm_description=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;t=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;h=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;story_title=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Introduction%20to%20PHP%20%E2%80%93%20Part8%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;submitHeadline=Introduction%20to%20PHP%20%E2%80%93%20Part8&amp;submitSummary=Function%3A%0D%0AA%20function%20is%20a%20subprogram%20that%20performs%20a%20specific%20task%20when%20called%20by%20the%20main%20program.%20It%20is%20always%20a%20good%20practice%20to%20divide%20a%20huge%20program%20into%20a%20number%20of%20subprograms%20until%20elementary%20functions%20are%20reached.%20More%20clearly%2C%20a%20huge%20progr&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fintroduction-to-php-%25e2%2580%2593-part8%2F&amp;title=Introduction%20to%20PHP%20%E2%80%93%20Part8" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/php/introduction-to-php-%e2%80%93-part8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Guide to OOP (Object Orientated Programming) in PHP Part 1</title>
		<link>http://www.w3updates.com/server-scripting/php/a-guide-to-oop-object-orientated-programming-in-php-part-1/</link>
		<comments>http://www.w3updates.com/server-scripting/php/a-guide-to-oop-object-orientated-programming-in-php-part-1/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 08:12:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.w3updates.com/?p=1308</guid>
		<description><![CDATA[In this part we’ll cover the basics of classes, and how to put together your own class. We’ll also go over how to make variables.
Classes add a lot of functionality to your code and help to stop you repeating yourself over and over again as you might in conventional code. With classes and functions you’ll [...]]]></description>
			<content:encoded><![CDATA[<p>In this part we’ll cover the basics of classes, and how to put together your own class. We’ll also go over how to make variables.</p>
<p>Classes add a lot of functionality to your code and help to stop you repeating yourself over and over again as you might in conventional code. With classes and functions you’ll be able to make generic scripts that you can simply call when you need them.</p>
<p>Not only this but classes make your coding a lot more tidy, so you can usually find everything you’re looking for. When you know how to use them they can really speed up the speed at which you’re working.<br />
Why should I learn OOP in PHP?</p>
<p>Well, sort of like real languages (sort of) once you know one programming language, its sort of similar across the board. Sure you’ll have the odd difference here and there, but there won’t be any really huge differences. Apart from that, PHP is one of the most widely used server side languages on the web, and it’ll definitely be worth your time learning to use objects in it.</p>
<p>Class is in Session</p>
<p>In Object Orientated Programming in PHP, we make classes. Classes are sets of functions that we can call when we need to, to use in our applications or websites. A class is pretty easy to make, just write class followed by the name you want to call that class. Then open (curly) brackets and close them at the end of the class. Here’s an example.</p>
<p>1.<br />
<?php<br />
2.</p>
<p>3.<br />
class name_goes_here {<br />
4.</p>
<p>5.<br />
}<br />
6.</p>
<p>7.<br />
?><br />
And there you have it, your first class. Are you proud of yourself? You should be! Lets add a function. These work the same way regular PHP funtions work. Just stick it inside the curly brackets.</p>
<p>01.<br />
<?php<br />
02.</p>
<p>03.<br />
class firstClass {<br />
04.</p>
<p>05.<br />
function myFunction($variable, $variable_2 = 1) {<br />
06.</p>
<p>07.<br />
if($variable = 1 &#038;&#038; $variable_2 = 1) {<br />
08.<br />
echo"Hello World";<br />
09.<br />
}<br />
10.</p>
<p>11.<br />
}<br />
12.</p>
<p>13.<br />
}<br />
14.</p>
<p>15.<br />
?><br />
Don’t understand functions? Let me explain. Functions are declared by writing the word function, followed by the name you wish to call it and two curly brackets. Inside the curly brackets you can add variables inside these brackets, which help you add additional settings to that function.</p>
<p>For instance, I could have a variable in the curly brackets, called “$variable”. It would be required that I define this variable when calling the function (we’ll get to that later). We can then use that variable inside the function, so that the variable can serve a different purpose in different cases. We can also set the variable to a default value which it will take if the user doesn’t define it, so we can put “$variable = 1″ in the brackets where 1 is the default value. If a default value is given, then you don’t have to define that variable when calling the function. Here’s an example:</p>
<p>01.<br />
<?php<br />
02.</p>
<p>03.<br />
function myFunction($variable, $variable_2 = 1) {<br />
04.</p>
<p>05.<br />
if($variable = 1 &#038;&#038; $variable_2 = 1) {<br />
06.<br />
echo"Hello World";<br />
07.<br />
}<br />
08.</p>
<p>09.<br />
}<br />
10.</p>
<p>11.<br />
?><br />
In the above $variable and $variable_2 must be set as 1 for the script to output “Hello World”. $variable_2 is already set as 1, so the user just has to set $variable as 1 for it to work (when calling the function).</p>
<p>So lets say, somewhere else in your file hierarchy you need to call that class and function. First we have to include the class file, and call a new instance of the class. Then we will call our function (myFunction) and define the variable $variable as 1 so that we’ll get the “Hello World” text.</p>
<p>01.<br />
<?php<br />
02.</p>
<p>03.<br />
include"class.php";<br />
04.</p>
<p>05.<br />
$class = new firstClass();<br />
06.</p>
<p>07.<br />
$class->myFunction($variable = 1);<br />
08.</p>
<p>09.<br />
?><br />
Basically, that’s all there is to it, if you just want to create basic classes and functions. You can have as many functions as you like, so this will work fine:</p>
<p>01.<br />
<?php<br />
02.</p>
<p>03.<br />
class myClass {<br />
04.</p>
<p>05.<br />
function functionOne() {<br />
06.<br />
}<br />
07.<br />
function functionTwo() {<br />
08.<br />
}<br />
09.<br />
function functionThree() {<br />
10.<br />
}<br />
11.</p>
<p>12.<br />
}<br />
13.<br />
?><br />
Just call the functions in the same manner as we did before.</p>
<p>Variables variables variables variables</p>
<p>Classes can have variables. In PHP5 to define a variable in a class you would do something like this:</p>
<p>01.<br />
<?php<br />
02.</p>
<p>03.<br />
class myClass {<br />
04.</p>
<p>05.<br />
public $var;<br />
06.<br />
public $house = "312";<br />
07.</p>
<p>08.<br />
function myFunction() {<br />
09.</p>
<p>10.<br />
}<br />
11.</p>
<p>12.<br />
}<br />
13.</p>
<p>14.<br />
?><br />
There are actually three ways you can declare a variable. You can change the public keyword to private or protected. In PHP4 you would have used the keyword var, which is now deprecated. However if you use it in PHP5 it will be as if you used public. You can use these keywords with functions as well, for example:</p>
<p>01.<br />
<?php<br />
02.</p>
<p>03.<br />
class myClass {<br />
04.</p>
<p>05.<br />
public myFunction() {<br />
06.<br />
}<br />
07.</p>
<p>08.<br />
}<br />
09.<br />
?><br />
By default however, all functions in a class are defined as public, so you do not need to write public beside every function.</p>
<p>But what do these words mean?<br />
Public is basically the default mode, and will allow you to do everything we’ve explained so far. It makes no difference to your coding if you’re using just public.<br />
Private means that the function or variable can only be accessed from inside that class (we’ll get to calling stuff inside a class next). This means that if you have a private function, you won’t be able to do this as it is outside the class it originated from:</p>
<p>01.<br />
<?php<br />
02.</p>
<p>03.<br />
include"class.php";<br />
04.</p>
<p>05.<br />
$class = new firstClass();<br />
06.</p>
<p>07.<br />
$class->myFunction($variable = 1);<br />
08.</p>
<p>09.<br />
?><br />
It also means (when we get to it) you can’t use private functions or variables in a child class. Public also allows the outside world to access/alter it, whereas private does not.<br />
Protected is sort of a hybrid mode, in that if you have a protected variable it will act as public inside the class and that classes child class (if any), but will be private outside of that.</p>
<p>Calling stuff inside a Class</p>
<p>This is pretty basic stuff. We’ve learned how to create variables, classes and functions so far, but how do we actually use that stuff together? You may have noticed that when we included the class and declared a function we used a new operator which looked like an arrow (->). We use this to call stuff inside a class too. Lets say we have an empty variable at the top of our class and we need to call it inside a function in that class. We use a special variable called $this followed by our new arrow operator and the variable name. Look, here’s an example:</p>
<p>01.<br />
<?php<br />
02.</p>
<p>03.<br />
class myClass {<br />
04.</p>
<p>05.<br />
public $variable;<br />
06.</p>
<p>07.<br />
function myFunction() {<br />
08.<br />
$this->variable = &#8220;Hello There&#8221;;<br />
09.<br />
print $this->variable;<br />
10.<br />
}<br />
11.</p>
<p>12.<br />
}<br />
13.</p>
<p>14.<br />
?><br />
The same thing will work with functions; for instance, if you have two functions and you want to call one inside another, just do this:</p>
<p>01.<br />
<?php<br />
02.</p>
<p>03.<br />
class myClass {<br />
04.</p>
<p>05.<br />
function functionOne() {<br />
06.<br />
echo"Hello World";<br />
07.<br />
}<br />
08.<br />
function functionTwo() {<br />
09.<br />
$this->functionOne();<br />
10.<br />
echo&#8221; my name is Johnny&#8221;;<br />
11.<br />
}<br />
12.<br />
}<br />
13.</p>
<p>14.<br />
?><br />
Instead of trying to overload you with information, I’ve decided to do this as a tutorial series, in different parts so you don’t get too much information at once. You should be able to make your own simple classes with this information.</p>
<p>Anyway, mess around with the information I’ve given you so far. Hopefully you should be able to make your own little creations. Until next time, my friend.</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;bodytext=In%20this%20part%20we%E2%80%99ll%20cover%20the%20basics%20of%20classes%2C%20and%20how%20to%20put%20together%20your%20own%20class.%20We%E2%80%99ll%20also%20go%20over%20how%20to%20make%20variables.%0D%0A%0D%0AClasses%20add%20a%20lot%20of%20functionality%20to%20your%20code%20and%20help%20to%20stop%20you%20repeating%20yourself%20over%20and%20over%20again%20as%20yo" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;notes=In%20this%20part%20we%E2%80%99ll%20cover%20the%20basics%20of%20classes%2C%20and%20how%20to%20put%20together%20your%20own%20class.%20We%E2%80%99ll%20also%20go%20over%20how%20to%20make%20variables.%0D%0A%0D%0AClasses%20add%20a%20lot%20of%20functionality%20to%20your%20code%20and%20help%20to%20stop%20you%20repeating%20yourself%20over%20and%20over%20again%20as%20yo" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;t=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;annotation=In%20this%20part%20we%E2%80%99ll%20cover%20the%20basics%20of%20classes%2C%20and%20how%20to%20put%20together%20your%20own%20class.%20We%E2%80%99ll%20also%20go%20over%20how%20to%20make%20variables.%0D%0A%0D%0AClasses%20add%20a%20lot%20of%20functionality%20to%20your%20code%20and%20help%20to%20stop%20you%20repeating%20yourself%20over%20and%20over%20again%20as%20yo" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;headline=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=In%20this%20part%20we%E2%80%99ll%20cover%20the%20basics%20of%20classes%2C%20and%20how%20to%20put%20together%20your%20own%20class.%20We%E2%80%99ll%20also%20go%20over%20how%20to%20make%20variables.%0D%0A%0D%0AClasses%20add%20a%20lot%20of%20functionality%20to%20your%20code%20and%20help%20to%20stop%20you%20repeating%20yourself%20over%20and%20over%20again%20as%20yo" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;bm_description=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;t=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;h=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;story_title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;submitHeadline=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201&amp;submitSummary=In%20this%20part%20we%E2%80%99ll%20cover%20the%20basics%20of%20classes%2C%20and%20how%20to%20put%20together%20your%20own%20class.%20We%E2%80%99ll%20also%20go%20over%20how%20to%20make%20variables.%0D%0A%0D%0AClasses%20add%20a%20lot%20of%20functionality%20to%20your%20code%20and%20help%20to%20stop%20you%20repeating%20yourself%20over%20and%20over%20again%20as%20yo&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fa-guide-to-oop-object-orientated-programming-in-php-part-1%2F&amp;title=A%20Guide%20to%20OOP%20%28Object%20Orientated%20Programming%29%20in%20PHP%20Part%201" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/php/a-guide-to-oop-object-orientated-programming-in-php-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MIXER : Social Networking Script</title>
		<link>http://www.w3updates.com/server-scripting/mixer-social-networking-script/</link>
		<comments>http://www.w3updates.com/server-scripting/mixer-social-networking-script/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 16:02:06 +0000</pubDate>
		<dc:creator>alyaspk</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Scripting]]></category>
		<category><![CDATA[mixer]]></category>
		<category><![CDATA[mixer script]]></category>
		<category><![CDATA[network script]]></category>
		<category><![CDATA[php script]]></category>
		<category><![CDATA[php scripts]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[social network script]]></category>
		<category><![CDATA[social networking script]]></category>
		<category><![CDATA[social script]]></category>

		<guid isPermaLink="false">http://w3updates.com/?p=1301</guid>
		<description><![CDATA[Young generation needs a special means of communicating and MIXER!! is the best choice among the community scripts! With it you get free:

 1) Video Chat, 2) VOIP Phone, 3) Video Sharing Module, 4) Flash Games, 5) Friends Module, 6) Flash Chat with Multiple Rooms, 7) 3D Chat,  Groups, 9) Classifieds, 10) Events, 11) [...]]]></description>
			<content:encoded><![CDATA[<p>Young generation needs a special means of communicating and MIXER!! is the best choice among the community scripts! With it you get free:<br />
<span id="more-1301"></span><br />
 1) Video Chat, 2) VOIP Phone, 3) Video Sharing Module, 4) Flash Games, 5) Friends Module, 6) Flash Chat with Multiple Rooms, 7) 3D Chat, <img src='http://www.w3updates.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> Groups, 9) Classifieds, 10) Events, 11) Greetings&#8217; Recording, 12) Photo Gallery, 13) Forum, 14) Blogs etc. </p>
<p>And what is more important, 3D City also goes free now. If you have a community or dating site you need to have something to attract customers. Day by day. Having a real 3D City live chat software on your site is sure to bring you a lot of new visitors. A new menu item will be added to your page: 3D City. The customer clicks on it and comes to an online virtual world, inhabited by other visitors of your site. They can chat and walk there together. After you purchase the internet 3D chat software, we will install it on your site free of charge. We will connect it to your user&#8217;s database seamlessly.<br />
<!--adsense--></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script&amp;bodytext=Young%20generation%20needs%20a%20special%20means%20of%20communicating%20and%20MIXER%21%21%20is%20the%20best%20choice%20among%20the%20community%20scripts%21%20With%20it%20you%20get%20free%3A%0D%0A%0D%0A%201%29%20Video%20Chat%2C%202%29%20VOIP%20Phone%2C%203%29%20Video%20Sharing%20Module%2C%204%29%20Flash%20Games%2C%205%29%20Friends%20Module%2C%206%29%20Flash%20Chat%20with" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script&amp;notes=Young%20generation%20needs%20a%20special%20means%20of%20communicating%20and%20MIXER%21%21%20is%20the%20best%20choice%20among%20the%20community%20scripts%21%20With%20it%20you%20get%20free%3A%0D%0A%0D%0A%201%29%20Video%20Chat%2C%202%29%20VOIP%20Phone%2C%203%29%20Video%20Sharing%20Module%2C%204%29%20Flash%20Games%2C%205%29%20Friends%20Module%2C%206%29%20Flash%20Chat%20with" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;t=MIXER%20%3A%20Social%20Networking%20Script" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script&amp;annotation=Young%20generation%20needs%20a%20special%20means%20of%20communicating%20and%20MIXER%21%21%20is%20the%20best%20choice%20among%20the%20community%20scripts%21%20With%20it%20you%20get%20free%3A%0D%0A%0D%0A%201%29%20Video%20Chat%2C%202%29%20VOIP%20Phone%2C%203%29%20Video%20Sharing%20Module%2C%204%29%20Flash%20Games%2C%205%29%20Friends%20Module%2C%206%29%20Flash%20Chat%20with" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=MIXER%20%3A%20Social%20Networking%20Script&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;headline=MIXER%20%3A%20Social%20Networking%20Script&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=Young%20generation%20needs%20a%20special%20means%20of%20communicating%20and%20MIXER%21%21%20is%20the%20best%20choice%20among%20the%20community%20scripts%21%20With%20it%20you%20get%20free%3A%0D%0A%0D%0A%201%29%20Video%20Chat%2C%202%29%20VOIP%20Phone%2C%203%29%20Video%20Sharing%20Module%2C%204%29%20Flash%20Games%2C%205%29%20Friends%20Module%2C%206%29%20Flash%20Chat%20with" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;bm_description=MIXER%20%3A%20Social%20Networking%20Script&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;t=MIXER%20%3A%20Social%20Networking%20Script" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=MIXER%20%3A%20Social%20Networking%20Script&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;h=MIXER%20%3A%20Social%20Networking%20Script" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=MIXER%20%3A%20Social%20Networking%20Script&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;story_title=MIXER%20%3A%20Social%20Networking%20Script" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=MIXER%20%3A%20Social%20Networking%20Script%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;submitHeadline=MIXER%20%3A%20Social%20Networking%20Script&amp;submitSummary=Young%20generation%20needs%20a%20special%20means%20of%20communicating%20and%20MIXER%21%21%20is%20the%20best%20choice%20among%20the%20community%20scripts%21%20With%20it%20you%20get%20free%3A%0D%0A%0D%0A%201%29%20Video%20Chat%2C%202%29%20VOIP%20Phone%2C%203%29%20Video%20Sharing%20Module%2C%204%29%20Flash%20Games%2C%205%29%20Friends%20Module%2C%206%29%20Flash%20Chat%20with&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmixer-social-networking-script%2F&amp;title=MIXER%20%3A%20Social%20Networking%20Script" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/mixer-social-networking-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make a Calendar in PHP</title>
		<link>http://www.w3updates.com/server-scripting/make-a-calendar-in-php/</link>
		<comments>http://www.w3updates.com/server-scripting/make-a-calendar-in-php/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 12:31:17 +0000</pubDate>
		<dc:creator>alyaspk</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Scripting]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[calendar in php]]></category>
		<category><![CDATA[calender]]></category>
		<category><![CDATA[make calendar]]></category>
		<category><![CDATA[php calandar]]></category>
		<category><![CDATA[php calendar]]></category>
		<category><![CDATA[php calender]]></category>
		<category><![CDATA[php hack]]></category>

		<guid isPermaLink="false">http://w3updates.com/?p=474</guid>
		<description><![CDATA[
Hello, and welcome to another PHP tutorial. This one will teach you how to make a nice PHP calendar (in PHP of course!). When I started out in PHP I always wanted to know how to make a calendar, but could never find the tutorial to do it. So i figured I’d write my own [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://webtint.net/wp-content/uploads/2009/07/calendar.png" alt="" width="403" height="128" /></p>
<p>Hello, and welcome to another PHP tutorial. This one will teach you how to make a nice PHP calendar (in PHP of course!). When I started out in PHP I always wanted to know how to make a calendar, but could never find the tutorial to do it. So i figured I’d write my own up, to help anyone who is in a similar situation to what I was in. Click the read link to find out more.<br />
<span id="more-474"></span></p>
<p><strong>Step 1. Getting Started and defining variables</strong></p>
<p>If you’re a bit rusty, or are new to PHP you might want to check out our Short beginners guide, to get the basics down before you start this tutorial. Start the PHP document as you’d start any other, with a PHP open and close tag:</p>
<p>[sourcecode language="php"]<br />
<?php</p>
<p>?><br />
[/sourcecode]</p>
<p>After that I decided to get the main variables sorted out. This is also pretty easy, it just requires some knowledge of the date and time functions. First of all, I decided that my PHP Calendar would be dynamic, as in, I could go through the months, and even the years.</p>
<p>So first, what I did was to get the ?month= part of the url.<br />
 [sourcecode language="php"]</p>
<p>if($_GET['month']) {<br />
	$month = $_GET['month'];<br />
}<br />
else {<br />
	$month = date(&#8216;n&#8217;);<br />
	$_GET['month'] = date(&#8216;n&#8217;);<br />
}<br />
[/sourcecode]</p>
<p>Okay I’m sure this must look difficult, but let me explain it line by line.<br />
[sourcecode language="php"]<br />
if($_GET['month']) {<br />
[/sourcecode]</p>
<p>What we’re saying there, is if we can get the month from the url, then we will do whatever is inside the curly brackets. $_GET is a global variable, and month is what we’re trying to get from the url.</p>
<p>[sourcecode language="php"]<br />
	$month = $_GET['month'];<br />
}<br />
[/sourcecode]</p>
<p>Then what we do is we put the month (which we get from the url again) into a variable called month, and close the if statement with a curly bracket.<br />
[sourcecode language="css"]</p>
<p>else {<br />
	$month = date(&#8216;n&#8217;);<br />
	$_GET['month'] = date(&#8216;n&#8217;);<br />
}<br />
[/sourcecode]</p>
<p>Otherwise (else), we set the month variable to the current month, as a default value if no other value is given. We also set $_GET['month'] to the current month (that’s what the date(’n&#8217;) bit does, it gets a numerical value for the month). You can’t see it in the url this time, but it is there. If you’re new to the whole date() function shindig, you might wanna check out this page: PHP Date Function. Next I did the same for the year:</p>
<p>[sourcecode language="php"]</p>
<p>if($_GET['year']) {<br />
	$year = $_GET['year'];<br />
}<br />
else {<br />
	$year = date(&#8216;Y&#8217;); // Year<br />
	$_GET['year'] = date(&#8216;Y&#8217;);<br />
}<br />
[/sourcecode]</p>
<p>Okay, if you understood the last bit, you should probably understand this bit. We’re doing exactly the same thing here only with the year. We’re saying, if we can get the year from the url, then put it in a variable. Otherwise, the year is the default year (current year, thats what date(’Y&#8217;) does, again.), and so is $_GET['year'] since it is not defined. Now that we have all this url business sorted out, let me give you an example of a url. Say that you are viewing July 2006. The url would look something like this: ?month=7&#038;year=2006. See how that works? July is the 7th month, and the year is 2006. Lets move on. Next I defined 4 more variables, that control the date, etc.<br />
[sourcecode language="php"]<br />
$firstday = mktime(0, 0, 0, $month, 1, $year);<br />
$number = cal_days_in_month(CAL_GREGORIAN, $month, $year); // Number of Days in a Month<br />
$title = date(&#8216;F&#8217;, $firstday); // Month name<br />
$day = date(&#8216;D&#8217;, $firstday); // Day<br />
[/sourcecode]</p>
<p>This might look a bit daunting at first, but lets break it down.<br />
$firstday = mktime(0, 0, 0, $month, 1, $year);<br />
[/sourcecode]</p>
<p>All that the above variable does is gets the first day of the current month (and year), as something called a unix timestamp.<br />
[sourcecode language="php"]<br />
$number = cal_days_in_month(CAL_GREGORIAN, $month, $year); // Number of Days in a Month<br />
[/sourcecode]</p>
<p>Another basic function, which gets the number of days in the month, using the gregorian calendar.<br />
[sourcecode language="php"]<br />
$title = date(&#8216;F&#8217;, $firstday); // Month name<br />
$day = date(&#8216;D&#8217;, $firstday); // Day<br />
[/sourcecode]</p>
<p>These lines find the month name using the timestamp we defined earlier as $firstday, and the name of the first day, again, using the timestamp we got earlier. Now that we’ve got the basic data defined, lets move on to some more intricate stuff.</p>
<p><strong>Step 2. Finding out what the first day is called</strong></p>
<p>So next we’re going to find out what the first day is, and then set a break before that. This is so that we don’t end up with the 1st beng a thursday, and then displaying in a column which should be for sundays.</p>
<p>[sourcecode language="php"]</p>
<p>if($day == &#8220;Sun&#8221;) {<br />
	$before = &#8220;0&#8243;;<br />
}<br />
elseif($day == &#8220;Mon&#8221;) {<br />
	$before = &#8220;1&#8243;;<br />
}</p>
<p>elseif($day == &#8220;Tue&#8221;) {<br />
	$before = &#8220;2&#8243;;<br />
}</p>
<p>elseif($day == &#8220;Wed&#8221;) {<br />
	$before = &#8220;3&#8243;;<br />
}</p>
<p>elseif($day == &#8220;Thu&#8221;) {<br />
	$before = &#8220;4&#8243;;<br />
}</p>
<p>elseif($day == &#8220;Fri&#8221;) {<br />
	$before = &#8220;5&#8243;;<br />
}</p>
<p>elseif($day == &#8220;Sat&#8221;) {<br />
	$before = &#8220;6&#8243;;<br />
}<br />
[/sourcecode]</p>
<p>This is actually pretty straight forward. We’re just setting a variable called before, depending on what day the first day of the month is. If the first day of the month is Sunday, then there is no need to move the calandar at all, therefore, “before” is zero, because sunday is the first day of the week. However, if it’s Wednesday, and we dont set a break, then it will appear in the first column, which is supposed to be for Sunday. Therefore we need 3 breaks (in the 4th column), where wednesday should be. So we set “before” as 3, for 3 breaks.</p>
<p><strong>Setting the scene</strong></p>
<p>Okay, so I mentioned earlier that I want this to be a dynamic calendar. So we’re going to need links, to move between the different months. This is a pretty straight forward part of code. I’ll show you the links first, and then we’ll define the variables.</p>
<p>[sourcecode language="php"]<br />
echo&#8221;<a href='?month=$previousmonth&#038;year=$previousyear'>&laquo;</a>&#8220;;<br />
echo&#8221;&nbsp; $title $year &nbsp;&#8221;;<br />
echo&#8221;<a href='?month=$nextmonth&#038;year=$nextyear'>&raquo;</a>&#8220;;<br />
[/sourcecode]</p>
<p>I don’t think this needs much explaining. All we’re doing here is echoing out variables that we made previously, well, apart from $previousmonth, $nextmonth, $previousyear and $nextyear. However, lets define those now. Put all of this above the links and title we just made.</p>
<p>[sourcecode language="php"]</p>
<p>if($_GET['month'] == 12) {<br />
	$nextmonth = 1;<br />
	$previousmonth = $_GET['month'] &#8211; 1;<br />
	$nextyear = $_GET['year'] + 1;<br />
	$previousyear = $_GET['year'];<br />
}<br />
[/sourcecode]</p>
<p>To start, what I did was to figure out whether or not this was the 12th month (december). After that I started defining variables. It makes sense logically, that if this month is the 12th month, then the next month will be January, or the first month, and that’s why $nextmonth is 1. However, the $previousmonth will be the current month (which we get from the url), minus 1. If we decided to go to the next year by pressing the next button, it will be the current year (which we get from the url), plus 1. Whereas, the previous year will just be the same, because going back will bring you to november, which is still in the same year. Another important thing to think about is if the month is January:<br />
[sourcecode language="php"]<br />
elseif($_GET['month'] == 1) {<br />
	$previousmonth = 12;<br />
	$nextmonth = $_GET['month'] + 1;<br />
	$previousyear = $_GET['year'] &#8211; 1;<br />
	$nextyear = $_GET['year'];<br />
}<br />
[/sourcecode]</p>
<p>So what we’re saying here, is if the month is 1 (elseif), then the previous month is going to be 12, logically. Whereas the next month is going to be the current month, plus 1. The previous year will be the current year, minus one, and next year will be the current year, since the next month is February, which is in the same year as January (1st month). Finally, we’ll finish with the else statement<br />
[sourcecode language="php"]<br />
else {<br />
	$nextmonth = $_GET['month'] + 1;<br />
	$previousmonth = $_GET['month'] &#8211; 1;<br />
	$nextyear = $_GET['year'];<br />
	$previousyear = $_GET['year'];<br />
}<br />
[/sourcecode]</p>
<p>So if the month is neither january or december, then the next month will just be the current month + 1, the previous month will be the current month – 1, and the next and previous year will stay the same. Remember to put all of this above the links we made before, or else it won’t work.</p>
<p><strong>Looping it all out</strong></p>
<p>To start this I defined two variables that I will use in the loops:</p>
<p>[sourcecode language="php"]<br />
$i = 1;<br />
$real = 1 + $before;<br />
[/sourcecode]</p>
<p>we’ll explain these later, when we’re doing the loops. After that I made a table. As much as it pains me to make a table, I felt it was easier than doing a bunch of divs. You’re welcome to change the table to divs if you want.<br />
[sourcecode language="php"]</p>
<p>echo&#8221;<br />
<table cellpadding='10'>
<tr>&#8220;;<br />
[/sourcecode]</p>
<p>Right, so lets make a loop.<br />
[sourcecode language="php"]</p>
<p>while($before > 0) {<br />
	echo&#8221;
<td> </td>
<p>&#8220;;<br />
	&#8211;$before;<br />
}<br />
[/sourcecode]<br />
Okay, so this is where we make the breaks, that I was explaining earlier. We want to leave blank spaces so that Wednesday doesn’t appear in a column which is for Sunday. Let me explain it, line by line<br />
[sourcecode language="php"]<br />
while($before > 0) {<br />
[/sourcecode]<br />
All we’re doing here is checking if the $before variable (remember, we defined it earlier) is more than zero, then the loop will continue.</p>
<p>[sourcecode language="php"]</p>
<p>	echo&#8221;
<td> </td>
<p>&#8220;;<br />
	&#8211;$before;<br />
}<br />
[/sourcecode]<br />
If it is more than zero, then take 1 away from the before variable, and show an empty table</p>
<p>element. This will show the correct number of blank spaces, so that we don’t end up with the problem i explained earlier.</p>
<p>[sourcecode language="php"]<br />
while($i <= $number) {</p>
<p>	echo"
<td> $i </td>
<p>&#8220;;</p>
<p>	$divide = $real / 7;<br />
	if(is_int($divide)) {<br />
		echo&#8221;</tr>
<tr>&#8220;;<br />
	}<br />
	++$real;<br />
	++$i;<br />
}<br />
[/sourcecode]</p>
<p>We’re nearly done now. Let me explain this loop.<br />
[sourcecode language="php"]<br />
while($i <= $number) {<br />
[/sourcecode]</p>
<p>So we’re saying, while $i (which is equal to 1) is less than or equal to (<=) the number of days in the month selected ($number), then the loop will continue.<br />
[sourcecode language="php"]<br />
	echo"
<td> $i </td>
<p>&#8220;;<br />
[/sourcecode]<br />
So first of all we echo out the number, or date in a</p>
<p>table element. However, if we left it like that, it would just be a straight line of numbers. We don’t really want that. To seperate the days by the week they’re in, we use a nifty little trick:</p>
<p>[sourcecode language="php"]<br />
$divide = $real / 7;<br />
[/sourcecode]<br />
You’ll remember that $real variable we defined earlier. Well we try and divide it by 7 here. Then..<br />
[sourcecode language="php"]<br />
if(is_int($divide)) {<br />
		echo&#8221;</tr>
<tr>&#8220;;<br />
	}<br />
[/sourcecode]</p>
<p>We check if it is an integer, using the is_int() function. An integer (you may or may not know) is a whole number. So if the $real variable is divisible by 7, then we make a break in the table, using the</p>
<p>elements.<br />
[sourcecode language="php"]<br />
	++$real;<br />
	++$i;<br />
}<br />
[/sourcecode]</p>
<p>Finally we add 1 to $real and $i using the ++ operator, so we don’t end up with an never ending loop. Then I closed the loop. To finish off, finish the table we started earlier:</p>
<p>[sourcecode language="php"]<br />
echo&#8221;</tr>
</table>
<p>&#8220;;<br />
?><br />
[/sourcecode]<br />
And we’re done. I hope this tutorial proved useful.</p>
<p><strong>Final Code</strong></p>
<p>[sourcecode language="php"]<br />
<?php</p>
<p>if($_GET['month']) {<br />
	$month = $_GET['month'];<br />
}<br />
else {<br />
	$month = date('n');<br />
	$_GET['month'] = date('n');<br />
}<br />
if($_GET['year']) {<br />
	$year = $_GET['year'];<br />
}<br />
else {<br />
	$year = date('Y'); // Year<br />
	$_GET['year'] = date('Y');<br />
}</p>
<p>$firstday = mktime(0, 0, 0, $month, 1, $year);<br />
$number = cal_days_in_month(CAL_GREGORIAN, $month, $year); // Number of Days in a Month<br />
$title = date('F', $firstday); // Month name<br />
$day = date('D', $firstday);</p>
<p>if($day == "Sun") {<br />
	$before = "0";<br />
}<br />
elseif($day == "Mon") {<br />
	$before = "1";<br />
}</p>
<p>elseif($day == "Tue") {<br />
	$before = "2";<br />
}</p>
<p>elseif($day == "Wed") {<br />
	$before = "3";<br />
}</p>
<p>elseif($day == "Thu") {<br />
	$before = "4";<br />
}</p>
<p>elseif($day == "Fri") {<br />
	$before = "5";<br />
}</p>
<p>elseif($day == "Sat") {<br />
	$before = "6";<br />
}</p>
<p>if($_GET['month'] == 12) {<br />
	$nextmonth = 1;<br />
	$previousmonth = $_GET['month'] - 1;<br />
	$nextyear = $_GET['year'] + 1;<br />
	$previousyear = $_GET['year'];<br />
}</p>
<p>elseif($_GET['month'] == 1) {<br />
	$previousmonth = 12;<br />
	$nextmonth = $_GET['month'] + 1;<br />
	$previousyear = $_GET['year'] - 1;<br />
	$nextyear = $_GET['year'];<br />
}</p>
<p>else {<br />
	$nextmonth = $_GET['month'] + 1;<br />
	$previousmonth = $_GET['month'] - 1;<br />
	$nextyear = $_GET['year'];<br />
	$previousyear = $_GET['year'];<br />
}</p>
<p>echo"<a href='?month=$previousmonth&#038;year=$previousyear'>&laquo;</a>&#8220;;<br />
echo&#8221;&nbsp; $title $year &nbsp;&#8221;;<br />
echo&#8221;<a href='?month=$nextmonth&#038;year=$nextyear'>&raquo;</a>&#8220;;</p>
<p>$i = 1;<br />
$real = 1 + $before;</p>
<p>echo&#8221;<br />
<table cellpadding='10'>
<tr>&#8220;;<br />
while($before > 0) {<br />
	echo&#8221;
<td> </td>
<p>&#8220;;<br />
	&#8211;$before;<br />
}</p>
<p>while($i <= $number) {</p>
<p>	echo"
<td> $i </td>
<p>&#8220;;</p>
<p>	$divide = $real / 7;<br />
	if(is_int($divide)) {<br />
		echo&#8221;</tr>
<tr>&#8220;;<br />
	}<br />
	++$real;<br />
	++$i;<br />
}</p>
<p>echo&#8221;</tr>
</table>
<p>&#8220;;</p>
<p>?><br />
[/sourcecode]</p>
<p><strong>Credit To : </strong><a href="http://webtint.net">http://webtint.net</a><br />
<!--adsense--></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP&amp;bodytext=%0D%0A%0D%0AHello%2C%20and%20welcome%20to%20another%20PHP%20tutorial.%20This%20one%20will%20teach%20you%20how%20to%20make%20a%20nice%20PHP%20calendar%20%28in%20PHP%20of%20course%21%29.%20When%20I%20started%20out%20in%20PHP%20I%20always%20wanted%20to%20know%20how%20to%20make%20a%20calendar%2C%20but%20could%20never%20find%20the%20tutorial%20to%20do%20it.%20So%20i%20fi" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP&amp;notes=%0D%0A%0D%0AHello%2C%20and%20welcome%20to%20another%20PHP%20tutorial.%20This%20one%20will%20teach%20you%20how%20to%20make%20a%20nice%20PHP%20calendar%20%28in%20PHP%20of%20course%21%29.%20When%20I%20started%20out%20in%20PHP%20I%20always%20wanted%20to%20know%20how%20to%20make%20a%20calendar%2C%20but%20could%20never%20find%20the%20tutorial%20to%20do%20it.%20So%20i%20fi" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;t=Make%20a%20Calendar%20in%20PHP" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP&amp;annotation=%0D%0A%0D%0AHello%2C%20and%20welcome%20to%20another%20PHP%20tutorial.%20This%20one%20will%20teach%20you%20how%20to%20make%20a%20nice%20PHP%20calendar%20%28in%20PHP%20of%20course%21%29.%20When%20I%20started%20out%20in%20PHP%20I%20always%20wanted%20to%20know%20how%20to%20make%20a%20calendar%2C%20but%20could%20never%20find%20the%20tutorial%20to%20do%20it.%20So%20i%20fi" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=Make%20a%20Calendar%20in%20PHP&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;headline=Make%20a%20Calendar%20in%20PHP&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=%0D%0A%0D%0AHello%2C%20and%20welcome%20to%20another%20PHP%20tutorial.%20This%20one%20will%20teach%20you%20how%20to%20make%20a%20nice%20PHP%20calendar%20%28in%20PHP%20of%20course%21%29.%20When%20I%20started%20out%20in%20PHP%20I%20always%20wanted%20to%20know%20how%20to%20make%20a%20calendar%2C%20but%20could%20never%20find%20the%20tutorial%20to%20do%20it.%20So%20i%20fi" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;bm_description=Make%20a%20Calendar%20in%20PHP&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;t=Make%20a%20Calendar%20in%20PHP" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=Make%20a%20Calendar%20in%20PHP&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;h=Make%20a%20Calendar%20in%20PHP" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Make%20a%20Calendar%20in%20PHP&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;story_title=Make%20a%20Calendar%20in%20PHP" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Make%20a%20Calendar%20in%20PHP%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;submitHeadline=Make%20a%20Calendar%20in%20PHP&amp;submitSummary=%0D%0A%0D%0AHello%2C%20and%20welcome%20to%20another%20PHP%20tutorial.%20This%20one%20will%20teach%20you%20how%20to%20make%20a%20nice%20PHP%20calendar%20%28in%20PHP%20of%20course%21%29.%20When%20I%20started%20out%20in%20PHP%20I%20always%20wanted%20to%20know%20how%20to%20make%20a%20calendar%2C%20but%20could%20never%20find%20the%20tutorial%20to%20do%20it.%20So%20i%20fi&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fmake-a-calendar-in-php%2F&amp;title=Make%20a%20Calendar%20in%20PHP" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/make-a-calendar-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automatically Highlight Admin Comments in Wordpress</title>
		<link>http://www.w3updates.com/server-scripting/php/automatically-highlight-admin-comments-in-wordpress/</link>
		<comments>http://www.w3updates.com/server-scripting/php/automatically-highlight-admin-comments-in-wordpress/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 07:54:23 +0000</pubDate>
		<dc:creator>alyaspk</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[admin comment]]></category>
		<category><![CDATA[comment highlight]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[highlight admin comment]]></category>
		<category><![CDATA[highlight comment]]></category>
		<category><![CDATA[php tipes]]></category>
		<category><![CDATA[php tutor]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress php]]></category>
		<category><![CDATA[wp]]></category>
		<category><![CDATA[wp comment]]></category>

		<guid isPermaLink="false">http://w3updates.com/?p=425</guid>
		<description><![CDATA[
In this follow up, we’re going to do better. The basis for this upgrade falls on a messy PHP “if…else” statement that was present in the old method. Below, we’ll explore two different methods for updating your blog’s admin highlighting system.

The Manual Array Method
This time around, we’re going to make it easy for ourselves to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://buildinternet.com/wp-content/uploads/admin-comments-banner.jpg" alt="" width="480" height="128" /><br />
In this follow up, we’re going to do better. The basis for this upgrade falls on a messy PHP “if…else” statement that was present in the old method. Below, we’ll explore two different methods for updating your blog’s admin highlighting system.<br />
<span id="more-425"></span><br />
<strong>The Manual Array Method</strong></p>
<p>This time around, we’re going to make it easy for ourselves to add in additional administrators without much additional code. Instead of using a bloated OR check for each email address, we’ll just have Wordpress run through a preset array containing all of the emails of blog administrators. If the email of a commenter also belongs to an administrator, the comment will be assigned a separate style to make it stand out.</p>
<p><strong>Build the Email Array</strong></p>
<p>Before we’re able to have comments highlighted, we’ll need to specify which emails deserve special treatment. I’ve used some of Sam and I’s email addresses as an example.</p>
<p>[sourcecode language="php"]<br />
<?php<br />
	//List of emails to highlight<br />
	$admin_emails = array(<br />
		"zach@buildinternet.com",<br />
		"sam@buildinternet.com",<br />
		"zach@onemightyroar.com",<br />
		"sam@onemightyroar.com"<br />
	);<br />
?><br />
[/sourcecode]</p>
<p><strong>You’ve Got Options</strong></p>
<p>Emails do not have to belong to a registered user in this method. If you have multiple email accounts, the array can check for all of them. This opens up many more options for expansion.</p>
<p>The downside to this route is the loss of automation. Each email addresses must be entered in manually by the blog administrator. It would be much easier to have Wordpress automatically detect the administrator accounts for the blog installation. That’s where the second option comes in.</p>
<p><strong>The Automated Database Method</strong></p>
<p>If we wanted to, we can code this so that we’ll never have to manually insert emails into the comments.php file once it’s been set up. We can have Wordpress pull all of the email addresses of registered users with privileges of Editor and Administrator. For most blogs, this will fit your needs just fine.</p>
<p><strong>Query the Database</strong></p>
<p>We’ll first need to get all of the admin emails from the database and place them into an array. This is easy to do using the<a href="http://codex.wordpress.org/Function_Reference/wpdb_Class"> Wordpress database object,</a> to query the database for specific users.</p>
<p>[sourcecode language="php"]<br />
<?php </p>
<p>	//Automatically pull admin accounts</p>
<p>	$user_level = 8; //Default user level (1-10)<br />
	$admin_emails = array(); //Hold Admin Emails</p>
<p>	//Search for the ID numbers of all accounts at specified user level and up<br />
	$admin_accounts = $wpdb->get_results(&#8220;SELECT * FROM $wpdb->usermeta WHERE meta_key = &#8216;wp_user_level&#8217; AND meta_value >= $user_level &#8220;);</p>
<p>	//Get the email address for each administrator via ID number<br />
	foreach ($admin_accounts as $admin_account){</p>
<p>		//Get database row for current user id<br />
		$admin_info = $wpdb->get_row(&#8220;SELECT * FROM $wpdb->users WHERE ID = $admin_account->user_id&#8221;);</p>
<p>		//Add current user&#8217;s email to array<br />
		$admin_emails[$admin_account->user_id] = $admin_info->user_email;<br />
	}</p>
<p>?><br />
[/sourcecode]</p>
<p>If this is your first experience with the Wordpress database object (or databases in general) the code above may seem a little bit confusing. Here’s a breakdown of what’s going on to help sort it out:</p>
<ul>
<li>The $user_level variable contains a number 1-10. <a href="http://codex.wordpress.org/Roles_and_Capabilities#level_10">Wordpress user roles</a> (e.g. Administrator, Editor, etc.) are all represented by a number value. To select Administrator accounts only, this number must be set to 8.</li>
<li>The $admin_emails array will hold the emails returned from the query.</li>
<li>The first database query searches the usermeta table for all users with a user level greater than or equal to the one stored in $user_level. The results are stored in the $admin_accounts array.</li>
<li>Each item in the $admin_accounts array is processed, and the user table is queried using the user id number pulled from step 3. The email address is retrieved and stored in the $admin_emails array using the user id as an identifier in the array.</li>
</ul>
<p>By the end of this code block, we have an array containing the email addresses of the specified user levels stored in $admin_emails. The nice part? This method will update itself when new users are registered. Just set it and forget it.</p>
<p><strong>Marking Administrator Comments</strong></p>
<p>At this point, both methods have the same next step. You’ll have an array of administrator emails stored in $admin_emails. We’ll need this as a reference when marking comments for special attention.</p>
<p><strong>Filter the Comments</strong></p>
<p>Now that we’ve got a list, we need to check each comment for admin email matches. If one is found, the comment will be assigned a class of “admincomment” and get different styling.</p>
<p>In the comments.php file of your blog theme, locate the foreach comment loop, and paste the following immediately under the start of it:</p>
<p>[sourcecode language="php"]<br />
<!--Check if comment is by the author--><br />
<?php<br />
	//Default to<br />
	$admin_comment = false;<br />
	foreach ($admin_emails as $admin_email){<br />
		//If comment was made from an admin email<br />
		if($comment->comment_author_email == $admin_email){<br />
			$admin_comment = true;<br />
                        break;<br />
		}<br />
	};<br />
?><br />
[/sourececode]</p>
<p>The above code grabs the comment author’s email address and checks it against those in the admin email array. If a match is found, $admin_comment is set to true.</p>
<p><strong>Assign Special Class to Comments</strong></p>
<p>Special comments are marked with a class of  “admincomment” by default. I’ve put a stripped down sample comment below to help you visualize. Pay special attention to the PHP included in the class attribute.<br />
[sourcecode language="php"] </p>
<li class="<?php if($admin_comment) echo 'admincomment'; ?>&#8220;><br />
	<!--Typical comment things here-->
</li>
<p>[/sourcecode]</p>
<p>Remember that the comment structure must be after the $isByAdmin loop in the previous step in order to work.<br />
<img src="http://buildinternet.com/wp-content/uploads/admin-comment-sample.jpg" alt="" /></p>
<p>Styling the Comments<br />
Giving administrator comments some extra flair is the easy part. In both methods above, you’ll end up with a class of “admincomment” on comments to highlight. Since you’ve got a specific class to target, giving it some special styling is just an extra CSS style away.</p>
<p>I’ve included a sample CSS snippet below to help you get started, but feel free to get creative on your final product.<br />
[sourcecode language="css"]<br />
.admincomment{background:#191919; color:#FFF; border:1px solid #333;}<br />
[/sourcecode]</p>
<p><strong>Download Code Snippets</strong></p>
<p>To help you along, I’ve put together a comment file with the necessary code snippets. It should help clear up any confusion left over about placement and ordering. You can grab the file using the link below:</p>
<p><strong>Download Source : </strong><a href="http://buildinternet.com/wp-content/uploads/admin-highlight-snippets.php.zip">Click Here</a></p>
<p><strong>Credit To : </strong><a href="http://buildinternet.com">http://buildinternet.com</a></p>
<p><!--adsense--></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;bodytext=%0D%0AIn%20this%20follow%20up%2C%20we%E2%80%99re%20going%20to%20do%20better.%20The%20basis%20for%20this%20upgrade%20falls%20on%20a%20messy%20PHP%20%E2%80%9Cif%E2%80%A6else%E2%80%9D%20statement%20that%20was%20present%20in%20the%20old%20method.%20Below%2C%20we%E2%80%99ll%20explore%20two%20different%20methods%20for%20updating%20your%20blog%E2%80%99s%20admin%20highlighting%20" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;notes=%0D%0AIn%20this%20follow%20up%2C%20we%E2%80%99re%20going%20to%20do%20better.%20The%20basis%20for%20this%20upgrade%20falls%20on%20a%20messy%20PHP%20%E2%80%9Cif%E2%80%A6else%E2%80%9D%20statement%20that%20was%20present%20in%20the%20old%20method.%20Below%2C%20we%E2%80%99ll%20explore%20two%20different%20methods%20for%20updating%20your%20blog%E2%80%99s%20admin%20highlighting%20" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;t=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;annotation=%0D%0AIn%20this%20follow%20up%2C%20we%E2%80%99re%20going%20to%20do%20better.%20The%20basis%20for%20this%20upgrade%20falls%20on%20a%20messy%20PHP%20%E2%80%9Cif%E2%80%A6else%E2%80%9D%20statement%20that%20was%20present%20in%20the%20old%20method.%20Below%2C%20we%E2%80%99ll%20explore%20two%20different%20methods%20for%20updating%20your%20blog%E2%80%99s%20admin%20highlighting%20" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;headline=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=%0D%0AIn%20this%20follow%20up%2C%20we%E2%80%99re%20going%20to%20do%20better.%20The%20basis%20for%20this%20upgrade%20falls%20on%20a%20messy%20PHP%20%E2%80%9Cif%E2%80%A6else%E2%80%9D%20statement%20that%20was%20present%20in%20the%20old%20method.%20Below%2C%20we%E2%80%99ll%20explore%20two%20different%20methods%20for%20updating%20your%20blog%E2%80%99s%20admin%20highlighting%20" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;bm_description=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;t=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;h=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;story_title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;submitHeadline=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress&amp;submitSummary=%0D%0AIn%20this%20follow%20up%2C%20we%E2%80%99re%20going%20to%20do%20better.%20The%20basis%20for%20this%20upgrade%20falls%20on%20a%20messy%20PHP%20%E2%80%9Cif%E2%80%A6else%E2%80%9D%20statement%20that%20was%20present%20in%20the%20old%20method.%20Below%2C%20we%E2%80%99ll%20explore%20two%20different%20methods%20for%20updating%20your%20blog%E2%80%99s%20admin%20highlighting%20&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fautomatically-highlight-admin-comments-in-wordpress%2F&amp;title=Automatically%20Highlight%20Admin%20Comments%20in%20Wordpress" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/php/automatically-highlight-admin-comments-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Introduction to Object Oriented PHP – Part 3</title>
		<link>http://www.w3updates.com/server-scripting/an-introduction-to-object-oriented-php-part-3/</link>
		<comments>http://www.w3updates.com/server-scripting/an-introduction-to-object-oriented-php-part-3/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 09:37:06 +0000</pubDate>
		<dc:creator>alyaspk</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Scripting]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[MySQLi]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[php 2]]></category>
		<category><![CDATA[php 3]]></category>
		<category><![CDATA[php great]]></category>
		<category><![CDATA[php hack]]></category>
		<category><![CDATA[php hack tutor]]></category>
		<category><![CDATA[php nice]]></category>
		<category><![CDATA[php object]]></category>
		<category><![CDATA[php object oriented]]></category>
		<category><![CDATA[php oriented]]></category>
		<category><![CDATA[php part 2]]></category>
		<category><![CDATA[php part 3]]></category>
		<category><![CDATA[php tutor]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Standards]]></category>

		<guid isPermaLink="false">http://w3updates.com/?p=337</guid>
		<description><![CDATA[
Introduction
Welcome to the third and final part of a series introducing Object Oriented PHP!

In this Tutorial
Today, we are going to finally complete the task that we’ve been leading up to: writing our MySQLi DB class! We’re going to be using everything we’ve learned so far to do this, so strap in and enjoy!

Variables and Constructor
Main [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://buildinternet.com/wp-content/uploads/oop-php-part3-banner.jpg" alt="" width="480" height="128" /></p>
<p><strong>Introduction</strong></p>
<p>Welcome to the third and final part of a series introducing Object Oriented PHP!<br />
<span id="more-337"></span><br />
<strong>In this Tutorial</strong></p>
<p>Today, we are going to finally complete the task that we’ve been leading up to: writing our MySQLi DB class! We’re going to be using everything we’ve learned so far to do this, so strap in and enjoy!</p>
<ul>
<li>Variables and Constructor</li>
<li>Main Functions</li>
<li>Some extra goodies</li>
</ul>
<p><strong>Variables and Constructor</strong></p>
<p>Create a new file called class.db.php and insert the following:</p>
<p>[sourcecode language="php"]<br />
<?php</p>
<p>/*<br />
* class db<br />
* @param Host<br />
* @param User<br />
* @param Password<br />
* @param Name<br />
*/<br />
class db<br />
{</p>
<p>	var $host;       //MySQL Host<br />
	var $user;       //MySQL User<br />
	var $pass;       //MySQL Password<br />
	var $name;       //MySQL Name</p>
<p>	var $mysqli;     //MySQLi Object</p>
<p>        var $last_query; //Last Query Run</p>
<p>	/*<br />
	 * Class Constructor<br />
	 * Creates a new MySQLi Object<br />
	 */<br />
	function __construct($host, $user, $pass, $name)<br />
	{</p>
<p>		$host = $this->host;<br />
		$user = $this->user;<br />
		$pass = $this->pass;<br />
		$name = $this->name;</p>
<p>		$this->mysqli = new mysqli($this->host, $this->user, $this->pass, $this->name);</p>
<p>	}</p>
<p>}</p>
<p>$db = new db(&#8216;localhost&#8217;, &#8216;root&#8217;, &#8221;, &#8216;blog&#8217;);</p>
<p>?><br />
[/sourcecode]</p>
<p>*Try and dissect what we have done here before reading the explanation!**</p>
<p>First, we have done the most important part of Object Oriented PHP – organization! We have said what the class name is, and all the parameters that need to be passed to it when it is loaded. Next, inside the class, we have defined our four variables for MySQL connection and then required them as parameters of the constructor function, which can be passed when the class is loaded at the bottom of the file. Next, we have set our $mysqli variable to a new MySQLi Object. Simple, right? Let’s move on.</p>
<p><strong>Main Functions</p>
<p>SELECT</strong></p>
<p>Now that we have the connection down, we can start working with the database. Add a select function like this:</p>
<p>[sourcecode language="php"]<br />
/*<br />
	 * Function Select<br />
	 * @param fields<br />
	 * @param from<br />
	 * @param where<br />
	 * @returns Query Result Set<br />
	 */<br />
	function select($fields, $from, $where)<br />
	{</p>
<p>		$query = &#8220;SELECT &#8221; . $fields . &#8221; FROM `&#8221; . $from . &#8220;` WHERE &#8221; . $where;<br />
		$result = $this->mysqli->query($query);</p>
<p>                $this->last_query = $query;</p>
<p>		return $result;</p>
<p>	}<br />
[/sourcecode]<br />
Here we have made a select function for selecting data from a MySQL table. We have defined three parameters, and you can see how they fit into the final query. All we return from this function is a query result set, which you can work with however you like in your pages.</p>
<p><strong>INSERT</strong></p>
<p>Of course, we can select data with our class now, but we don’t have anything to select unless we insert it! Let’s do that now by adding this function to your class:</p>
<p>[sourcecode language="php"]<br />
/*<br />
 * Function Insert<br />
 * @param into<br />
 * @param values<br />
 * @returns boolean<br />
 */<br />
function insert($into, $values)<br />
{</p>
<p>	$query = &#8220;INSERT INTO &#8221; . $into . &#8221; VALUES(&#8221; . $values . &#8220;)&#8221;;</p>
<p>        $this->last_query = $query;</p>
<p>	if($this->mysqli->query($query))<br />
	{<br />
		return true;<br />
	} else {<br />
		return false;<br />
	}</p>
<p>}<br />
[/sourecode]</p>
<p>Another quite simple function, we are just requiring two parameters: the table name to insert the data into, and the values for the fields. Instead of returning any real data for this function, we just go ahead and run it and if it inserted the data, it returns true, and if not, false. Simple for inserting data.</p>
<p><strong>DELETE</strong></p>
<p>Now that we can insert and then select our data, we have to have a way to delete it say if a user wanted to delete their account. Add this function:</p>
<p>[sourcecode language="php"]<br />
<?php</p>
<p>/*<br />
 * Function Delete<br />
 * @param from<br />
 * @param where<br />
 * @returns boolean<br />
 */<br />
function delete($from, $where)<br />
{</p>
<p>	$query = "DELETE FROM " . $from . " WHERE " . $where;</p>
<p>        $this->last_query = $query;</p>
<p>	if($this->mysqli->query($query))<br />
	{<br />
		return true;<br />
	} else {<br />
		return false;<br />
	}</p>
<p>}<br />
[/sourcecode]</p>
<p><strong>Some extra goodies</strong></p>
<p>You probably noticed the last_query variable we defined at the beginning of the class, then we set it every time we ran a query in a function. This is very vital for troubleshooting, to see what’s wrong with your query. Another possible class variable could be a last_error, that would hold the last error returned.</p>
<p><strong>Conclusion</strong></p>
<p>This will conclude this series on Object Oriented PHP – I hope you’ve at least learned the basics so you’ll be able to power up your applications! Thanks for reading.</p>
<p><strong>Credit To : </strong><a href="http://buildinternet.com/">http://www.buildinternet.com/</a></p>
<p><!--adsense--></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;bodytext=%0D%0A%0D%0AIntroduction%0D%0A%0D%0AWelcome%20to%20the%20third%20and%20final%20part%20of%20a%20series%20introducing%20Object%20Oriented%20PHP%21%0D%0A%0D%0AIn%20this%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20finally%20complete%20the%20task%20that%20we%E2%80%99ve%20been%20leading%20up%20to%3A%20writing%20our%20MySQLi%20DB%20class%21%20We%E2%80%99re%20going%20t" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;notes=%0D%0A%0D%0AIntroduction%0D%0A%0D%0AWelcome%20to%20the%20third%20and%20final%20part%20of%20a%20series%20introducing%20Object%20Oriented%20PHP%21%0D%0A%0D%0AIn%20this%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20finally%20complete%20the%20task%20that%20we%E2%80%99ve%20been%20leading%20up%20to%3A%20writing%20our%20MySQLi%20DB%20class%21%20We%E2%80%99re%20going%20t" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;t=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;annotation=%0D%0A%0D%0AIntroduction%0D%0A%0D%0AWelcome%20to%20the%20third%20and%20final%20part%20of%20a%20series%20introducing%20Object%20Oriented%20PHP%21%0D%0A%0D%0AIn%20this%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20finally%20complete%20the%20task%20that%20we%E2%80%99ve%20been%20leading%20up%20to%3A%20writing%20our%20MySQLi%20DB%20class%21%20We%E2%80%99re%20going%20t" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;headline=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=%0D%0A%0D%0AIntroduction%0D%0A%0D%0AWelcome%20to%20the%20third%20and%20final%20part%20of%20a%20series%20introducing%20Object%20Oriented%20PHP%21%0D%0A%0D%0AIn%20this%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20finally%20complete%20the%20task%20that%20we%E2%80%99ve%20been%20leading%20up%20to%3A%20writing%20our%20MySQLi%20DB%20class%21%20We%E2%80%99re%20going%20t" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;bm_description=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;t=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;h=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;story_title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;submitHeadline=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203&amp;submitSummary=%0D%0A%0D%0AIntroduction%0D%0A%0D%0AWelcome%20to%20the%20third%20and%20final%20part%20of%20a%20series%20introducing%20Object%20Oriented%20PHP%21%0D%0A%0D%0AIn%20this%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20finally%20complete%20the%20task%20that%20we%E2%80%99ve%20been%20leading%20up%20to%3A%20writing%20our%20MySQLi%20DB%20class%21%20We%E2%80%99re%20going%20t&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-3%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%203" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/an-introduction-to-object-oriented-php-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Introduction to Object Oriented PHP – Part 2</title>
		<link>http://www.w3updates.com/server-scripting/an-introduction-to-object-oriented-php-part-2/</link>
		<comments>http://www.w3updates.com/server-scripting/an-introduction-to-object-oriented-php-part-2/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 09:31:30 +0000</pubDate>
		<dc:creator>alyaspk</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Scripting]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[MySQLi]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[php 2]]></category>
		<category><![CDATA[php great]]></category>
		<category><![CDATA[php hack]]></category>
		<category><![CDATA[php nice]]></category>
		<category><![CDATA[php object]]></category>
		<category><![CDATA[php object oriented]]></category>
		<category><![CDATA[php oriented]]></category>
		<category><![CDATA[php part 2]]></category>
		<category><![CDATA[php tutor]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Standards]]></category>

		<guid isPermaLink="false">http://w3updates.com/?p=334</guid>
		<description><![CDATA[
Introduction
Welcome to Part 2 of a three part series introducing Object Oriented PHP!

In This Tutorial
Today, we are going to learn the following:

Constructors and Destructors
Returning data from your functions
Keeping organized

Constructors and Destructors
Think of PHP constructors and destructors like a building. You construct a building at first, then when you’re done using it, you destruct it. Except [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://buildinternet.com/wp-content/uploads/oop-php-part2-banner.jpg" alt="" width="480" height="128" /></p>
<p>Introduction<br />
Welcome to Part 2 of a three part series introducing Object Oriented PHP!<br />
<span id="more-334"></span><br />
<strong>In This Tutorial</strong></p>
<p>Today, we are going to learn the following:</p>
<ul>
<li>Constructors and Destructors</li>
<li>Returning data from your functions</li>
<li>Keeping organized</li>
</ul>
<p><strong>Constructors and Destructors</strong></p>
<p>Think of PHP constructors and destructors like a building. You construct a building at first, then when you’re done using it, you destruct it. Except in PHP, there are no live explosives for the destruction. Let’s look at the following example of constructors:<br />
[sourcecode language="php"]<br />
<?php<br />
class MyClass<br />
{<br />
   function __construct()<br />
   {<br />
      echo "MyClass Loaded!";<br />
   }<br />
}<br />
$MyClass = new MyClass();<br />
?><br />
[/sourcecode]<br />
In this example, we create a new class simply called MyClass, then a constructor function that says MyClass Loaded!. Basically, anything you want to happen when you call upon your class, should go in the constructor function.</p>
<p>In PHP, you don’t need to worry about always having a __destruct() method in your class, as all classes and variables are removed after your object is destroyed. (At the end of execution).</p>
<p><strong>Returning data from your functions</strong></p>
<p>In the real world, you don’t want to be using echo statements within your functions, you want to run your function and return the data for you to echo out where you want it. Let’s take a look at the following example that could be part of a blog application:</p>
<p>[sourcecode language="php"]<br />
<?php</p>
<p>class MyClass<br />
{</p>
<p>	var $mysqli;</p>
<p>	function __construct()<br />
	{</p>
<p>		$this->mysqli = new mysqli(&#8216;localhost&#8217;, &#8216;root&#8217;, &#8221;, &#8216;blog&#8217;);</p>
<p>	}</p>
<p>	function get_latest_posts()<br />
	{</p>
<p>		//Do some database selection<br />
		$query = &#8220;SELECT * FROM `posts` ORDER BY `id` DESC&#8221;;<br />
		$result = $this->mysqli->query($query);</p>
<p>		return $result;</p>
<p>	}</p>
<p>}</p>
<p>php?><br />
[/sourcecode]<br />
Here, we are using a constructor to make a new MySQLi connection, and then using that connection set in the constructor to run a possible query, then to return the result set to be used however you’d like to display the data. Simple, right?</p>
<p><strong>Keeping Organized</strong><br />
<img src="http://buildinternet.com/wp-content/uploads/intro-oop-knex-boxes.jpg" alt="" /></p>
<p>In the first <a href="http://w3updates.com/an-introduction-to-object-oriented-php-part-1/">part of this series</a>, I described classes as boxes, and functions as the things within the boxes. This picture is a great representation of keeping your classes well separated from each other, and their contents nicely arranged.</p>
<p>One key aspect of writing classes is to keep things easy to read and edit later. Let’s take a look at a f<a href="http://core.trac.wordpress.org/browser/trunk/wp-includes/wp-db.php">ile from the very popular blogging platform Wordpress.</a> As you can see,  above every variable declaration, class declaration, and function declaration, there is vital information about the parameters, what the function does, and what it returns. Let’s write our own example now:</p>
<p>[sourcecode language="php"]<br />
<?php</p>
<p>/*<br />
 * @name MyClass<br />
 * @params none<br />
 * Our database class that makes a new database connection, and   will insert userdata.<br />
 */<br />
class MyClass<br />
{</p>
<p>	/*<br />
	 * MySQLi Connection Link<br />
	 */<br />
	private $mysqli;</p>
<p>	/*<br />
	 * __construct<br />
	 * Sets new MySQLi Connection<br />
	 */<br />
	function __construct()<br />
	{</p>
<p>		$this->mysqli = new mysqli(&#8216;localhost&#8217;, &#8216;root&#8217;, &#8221;, &#8216;buildinternet&#8217;);</p>
<p>	}</p>
<p>	/*<br />
	 * insert_userdata<br />
	 * @params username, password<br />
	 * @returns bool<br />
	 */<br />
	function insert_userdata($username, $password)<br />
	{</p>
<p>		//Insert the userdata into the database<br />
		if(success)<br />
		{<br />
			return true;<br />
		} else {<br />
			return false;<br />
		}</p>
<p>	}</p>
<p>}</p>
<p>php?><br />
[/sourcecode]</p>
<p>Here, we have said what our class is, what it does, and then defined each function or variable within it. In the insert_userdata() function, we have said what the parameters are and what it returns above the function. As you can already see, these comments help immensely when trying to read your code or trying to find a problem with your code.</p>
<p><strong>Conclusion</strong></p>
<p>Now, after reading the second part in this series, we have all the skills we need to write our MySQLi Database interaction class in Part 3! Thanks for reading and be sure to check back for the third part!</p>
<p><strong>Credit To : </strong><a href="http://buildinternet.com/">http://www.buildinternet.com/</a></p>
<p><!--adsense--></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;bodytext=%0D%0A%0D%0AIntroduction%0D%0AWelcome%20to%20Part%202%20of%20a%20three%20part%20series%20introducing%20Object%20Oriented%20PHP%21%20%0D%0A%0D%0AIn%20This%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20learn%20the%20following%3A%0D%0A%0D%0A%0D%0A%09Constructors%20and%20Destructors%0D%0A%0D%0A%09Returning%20data%20from%20your%20functions%0D%0A%0D%0A%09Keeping%20orga" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;notes=%0D%0A%0D%0AIntroduction%0D%0AWelcome%20to%20Part%202%20of%20a%20three%20part%20series%20introducing%20Object%20Oriented%20PHP%21%20%0D%0A%0D%0AIn%20This%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20learn%20the%20following%3A%0D%0A%0D%0A%0D%0A%09Constructors%20and%20Destructors%0D%0A%0D%0A%09Returning%20data%20from%20your%20functions%0D%0A%0D%0A%09Keeping%20orga" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;t=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;annotation=%0D%0A%0D%0AIntroduction%0D%0AWelcome%20to%20Part%202%20of%20a%20three%20part%20series%20introducing%20Object%20Oriented%20PHP%21%20%0D%0A%0D%0AIn%20This%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20learn%20the%20following%3A%0D%0A%0D%0A%0D%0A%09Constructors%20and%20Destructors%0D%0A%0D%0A%09Returning%20data%20from%20your%20functions%0D%0A%0D%0A%09Keeping%20orga" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;headline=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=%0D%0A%0D%0AIntroduction%0D%0AWelcome%20to%20Part%202%20of%20a%20three%20part%20series%20introducing%20Object%20Oriented%20PHP%21%20%0D%0A%0D%0AIn%20This%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20learn%20the%20following%3A%0D%0A%0D%0A%0D%0A%09Constructors%20and%20Destructors%0D%0A%0D%0A%09Returning%20data%20from%20your%20functions%0D%0A%0D%0A%09Keeping%20orga" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;bm_description=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;t=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;h=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;story_title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;submitHeadline=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202&amp;submitSummary=%0D%0A%0D%0AIntroduction%0D%0AWelcome%20to%20Part%202%20of%20a%20three%20part%20series%20introducing%20Object%20Oriented%20PHP%21%20%0D%0A%0D%0AIn%20This%20Tutorial%0D%0A%0D%0AToday%2C%20we%20are%20going%20to%20learn%20the%20following%3A%0D%0A%0D%0A%0D%0A%09Constructors%20and%20Destructors%0D%0A%0D%0A%09Returning%20data%20from%20your%20functions%0D%0A%0D%0A%09Keeping%20orga&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-2%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%202" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/an-introduction-to-object-oriented-php-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Introduction to Object Oriented PHP – Part 1</title>
		<link>http://www.w3updates.com/server-scripting/an-introduction-to-object-oriented-php-part-1/</link>
		<comments>http://www.w3updates.com/server-scripting/an-introduction-to-object-oriented-php-part-1/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 09:20:16 +0000</pubDate>
		<dc:creator>alyaspk</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Scripting]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[introduction to php]]></category>
		<category><![CDATA[object oriednted]]></category>
		<category><![CDATA[object php]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[oriented]]></category>
		<category><![CDATA[oriented php]]></category>
		<category><![CDATA[php hack]]></category>
		<category><![CDATA[php tips]]></category>
		<category><![CDATA[php tricks]]></category>
		<category><![CDATA[php tutor]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Standards]]></category>

		<guid isPermaLink="false">http://w3updates.com/?p=332</guid>
		<description><![CDATA[
About This Series
This is a three part series introducing Object-Oriented PHP, a way to manage your code and keep different parts separate, all while being easily accessible.

By the end of this series, we are going to make a very simple MySQLi (MySQL Improved) database interaction class, for doing common tasks.
In this Tutorial

What the heck are [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://buildinternet.com/wp-content/uploads/oop-php-part1-banner.png" alt="" width="420" height="112" /></p>
<p><strong>About This Series</strong></p>
<p>This is a three part series introducing Object-Oriented PHP, a way to manage your code and keep different parts separate, all while being easily accessible.<br />
<span id="more-332"></span></p>
<p>By the end of this series, we are going to make a very simple MySQLi (MySQL Improved) database interaction class, for doing common tasks.</p>
<p><strong>In this Tutorial</strong></p>
<ul>
<li>What the heck are Objects and Classes?</li>
<li>Writing our first class</li>
<li>How to use your freshly written class</li>
<li>How to personalize it</li>
<li>Let’s get started!</li>
</ul>
<p><strong>What the heck are Objects and Classes?</strong></p>
<p>Classes, at their simplest point, are just receptacles of functions. They can be compared to a folder on your computer (assuming you aren’t running DOS). Inside the folder you may have three files, or in this case, functions. Let’s use a classic example, a Dog.</p>
<p>Take a look at the following image:<br />
<img src="http://buildinternet.com/wp-content/uploads/oop-php-part1-dog-example.png" alt="" /></p>
<p>As you can see, a Dog has many “functions”. It can run, walk, sit, play, and bark. This is the essence of what a class is.</p>
<p>An Object, on the other hand, is a way to represent your class. For example, you can have your class named “Dog”, but you can reference it by a variable called Cat if you really wanted to confuse yourself.</p>
<p>That’s all we’re going to cover in this section, so if you’re still confused, read on and I believe the examples will make some coherent sense.</p>
<p><strong>Writing our first class</strong></p>
<p>Since this is just our first class, we’re going to keep things nice and simple. Open up your text editor of choice and make a new file in your web root called myClass.php. Add in the following code:</p>
<p>[sourcecode language="php"]<br />
<?php<br />
class myClass<br />
{<br />
	function sayHello()<br />
	{<br />
		echo "Hello there!";<br />
	}<br />
}<br />
?><br />
[/sourcecode]</p>
<p>If you navigate to this file on your server, nothing will show up. All we did was set up a class (container) and add in a function, we never referenced it to be run.</p>
<p><strong>How to use your freshly written class</strong></p>
<p>Now that we have our myClass.php file all written, we’re going to reference it and use it. Make a new file in the same folder as your class is in, called index.php. Add in the following code:<br />
[sourcecode language="php"]<br />
<?php</p>
<p>	require_once('myClass.php');</p>
<p>	$myClass = new myClass();</p>
<p>	$myClass->sayHello();</p>
<p>?><br />
[/sourcecode]</p>
<p>If you run the file, you should see “Hello World!” echoed out. Let’s go over what we did to make this work. First, you can see that we required the myClass.php file, which contains our container full of functions. Next, we had to make a new Object, and we used the class name as the object name, just for ease of use. And finally, we referenced our sayHello function by writing the Object name with an arrow and the function name.</p>
<p><strong>Making it Friendlier</strong></p>
<p>Right now, if we wanted to use this to greet a logged in user, there wouldn’t be much of a sense of personalization, would there? Wouldn’t it be nice if we could say Hello to the specific user? Well, we can! Go back to your myClass.php file and edit it accordingly:</p>
<p>[sourcecode language="php"]<br />
<?php<br />
class myClass<br />
{<br />
	function sayHello($user)<br />
	{<br />
		echo "Hello " . $user . "!";<br />
	}<br />
}<br />
?><br />
[/sourcecode]</p>
<p>All we did was add a parameter to the function called name, that we can pass along to the function from our index file. Go back to your index.php file now and add your name like so:</p>
<p>[sourcecode language="php"]<br />
<?php</p>
<p>	require_once('myClass.php');</p>
<p>	$myClass = new myClass();</p>
<p>	$myClass->sayHello(&#8216;Dixon&#8217;);</p>
<p>?><br />
[/sourcecode]</p>
<p><strong>Conclusion</strong></p>
<p>Now that we’ve covered the very basics of Object-Oriented PHP, you can practically do it all. And was it hard? Hopefully not! Be sure to check in later for the rest of this series, in which we’ll be making a fully functional MySQLi Database interaction class! Thanks for reading.</p>
<p><strong>Credit To : </strong><a href="http://buildinternet.com/">http://www.buildinternet.com/</a></p>
<p><!--adsense--></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;bodytext=%0D%0A%0D%0AAbout%20This%20Series%0D%0A%0D%0AThis%20is%20a%20three%20part%20series%20introducing%20Object-Oriented%20PHP%2C%20a%20way%20to%20manage%20your%20code%20and%20keep%20different%20parts%20separate%2C%20all%20while%20being%20easily%20accessible.%20%0D%0A%0D%0A%0D%0ABy%20the%20end%20of%20this%20series%2C%20we%20are%20going%20to%20make%20a%20very%20simple%20" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;notes=%0D%0A%0D%0AAbout%20This%20Series%0D%0A%0D%0AThis%20is%20a%20three%20part%20series%20introducing%20Object-Oriented%20PHP%2C%20a%20way%20to%20manage%20your%20code%20and%20keep%20different%20parts%20separate%2C%20all%20while%20being%20easily%20accessible.%20%0D%0A%0D%0A%0D%0ABy%20the%20end%20of%20this%20series%2C%20we%20are%20going%20to%20make%20a%20very%20simple%20" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;t=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;annotation=%0D%0A%0D%0AAbout%20This%20Series%0D%0A%0D%0AThis%20is%20a%20three%20part%20series%20introducing%20Object-Oriented%20PHP%2C%20a%20way%20to%20manage%20your%20code%20and%20keep%20different%20parts%20separate%2C%20all%20while%20being%20easily%20accessible.%20%0D%0A%0D%0A%0D%0ABy%20the%20end%20of%20this%20series%2C%20we%20are%20going%20to%20make%20a%20very%20simple%20" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;headline=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=%0D%0A%0D%0AAbout%20This%20Series%0D%0A%0D%0AThis%20is%20a%20three%20part%20series%20introducing%20Object-Oriented%20PHP%2C%20a%20way%20to%20manage%20your%20code%20and%20keep%20different%20parts%20separate%2C%20all%20while%20being%20easily%20accessible.%20%0D%0A%0D%0A%0D%0ABy%20the%20end%20of%20this%20series%2C%20we%20are%20going%20to%20make%20a%20very%20simple%20" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;bm_description=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;t=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;h=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;story_title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;submitHeadline=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201&amp;submitSummary=%0D%0A%0D%0AAbout%20This%20Series%0D%0A%0D%0AThis%20is%20a%20three%20part%20series%20introducing%20Object-Oriented%20PHP%2C%20a%20way%20to%20manage%20your%20code%20and%20keep%20different%20parts%20separate%2C%20all%20while%20being%20easily%20accessible.%20%0D%0A%0D%0A%0D%0ABy%20the%20end%20of%20this%20series%2C%20we%20are%20going%20to%20make%20a%20very%20simple%20&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fan-introduction-to-object-oriented-php-part-1%2F&amp;title=An%20Introduction%20to%20Object%20Oriented%20PHP%20%E2%80%93%20Part%201" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/an-introduction-to-object-oriented-php-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaying Author Meta Information in Wordpress 2.8</title>
		<link>http://www.w3updates.com/server-scripting/php/displaying-author-meta-information-in-wordpress-2-8/</link>
		<comments>http://www.w3updates.com/server-scripting/php/displaying-author-meta-information-in-wordpress-2-8/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 10:11:28 +0000</pubDate>
		<dc:creator>alyaspk</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[author]]></category>
		<category><![CDATA[author meta]]></category>
		<category><![CDATA[author meta information]]></category>
		<category><![CDATA[author meta information wp]]></category>
		<category><![CDATA[author meta wordpres]]></category>
		<category><![CDATA[author meta wordpress]]></category>
		<category><![CDATA[author meta wp]]></category>
		<category><![CDATA[Blogging]]></category>
		<category><![CDATA[display meta author]]></category>
		<category><![CDATA[quick tip]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress author]]></category>
		<category><![CDATA[wordpress meta]]></category>
		<category><![CDATA[wordpress meta author]]></category>
		<category><![CDATA[wordpress tips]]></category>

		<guid isPermaLink="false">http://w3updates.com/?p=292</guid>
		<description><![CDATA[
One of the (many) nice updates the comes bundled in Wordpress 2.8 is with the_author_meta() template tag. This tag allows a developer to pull and display specific parts of any user’s information within a theme. Even though variations of this have been included in previous releases, this version has simplified it to a much easier [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://buildinternet.com/wp-content/uploads/author-meta-wp-28-banner.jpg" alt="" width="480" height="128" /><br />
One of the (many) nice updates the comes bundled in Wordpress 2.8 is with the_author_meta() template tag. This tag allows a developer to pull and display specific parts of any user’s information within a theme. Even though variations of this have been included in previous releases, this version has simplified it to a much easier syntax.<br />
<span id="more-292"></span></p>
<p>In this quick overview, we’ll look at some potential uses for the recently overhauled <a href="http://codex.wordpress.org/Template_Tags/the_author_meta">Author Meta template tag</a>. Keep in mind that all of these demonstrations are done within a Wordpress 2.8 installation. If you do not have this version running, these tags will not work as intended.</p>
<p><strong>Displaying the Data</strong></p>
<p>Especially if your site has registered users, this is an easy way to personalize your blog’s theme for each one. Let’s say you wanted to provide users a way to contact you by email:<br />
[sourcecode language="html"]</p>
<p>Get in touch with <a href="mailto:<?php the_author_meta('user_email'); ?>&#8220;><?php the_author_meta('user_firstname'); ?> via Email</a></p>
<p>[/sourcecode]</p>
<p>With the new author_meta options, information is displayed when the tag is called. If you’re looking to format the data first, you’ll need a different tag. Lucky for you, that’s exactly what the next section covers.</p>
<p><strong>Manipulating the Data</strong></p>
<p>Keep in mind that the_author_meta() tag is only meant to be used to display the contents. If you’re looking to manipulate or format the contents of a field, you’ll have to use a slightly different variation of the tag. This is where get_the_author_meta() comes in.</p>
<p>This template tag follows the same idea of retrieving author meta information, but it does not automatically display the contents. Here’s an example using date formatting:<br />
[sourcecode language="php"]<br />
<?php<br />
   //Format the author's registration date<br />
   $register_date = date("m/d/Y", strtotime(get_the_author_meta('user_registered')));<br />
?><br />
[/sourcecode]</p>
<p>And this code will give us a formatted output from the results:<br />
[sourcecode language="php"]</p>
<p><?php the_author_meta('user_firstname'); ?> has been with us since <?php echo $register_date; ?></p>
<p>[/sourcecode]</p>
<p>As you can see, the result finds the registration date of the user, and then formats it from the original timestamp into something much more pleasant to read. Not bad for a couple lines of code!</p>
<p><strong>Build an Updated Author Box</strong></p>
<p>The tags used there are now deprecated with this update, so let’s take a moment to refresh our code and stay fresh.<br />
<img src="http://buildinternet.com/wp-content/uploads/updated-author-box-wp-2-8.jpg" alt="" /></p>
<p>Originally, the code to render our author box with a gravatar, linked author name, and description looked something like this:<br />
[sourcecode language="php"]</p>
<div id="authorbox">
   <?php if (function_exists('get_avatar')) { echo get_avatar(get_the_author_email(), '80' ); }?></p>
<div>
<h4>About <?php the_author_posts_link(); ?></h4>
<p><?php the_author_description(); ?></p>
</p></div>
</div>
<p>[/sourcecode]<br />
As you can see, the previously used tags don’t really follow a single format. Now let’s take a look at the same result using the updated Wordpress 2.8 tags. For the sake of education, we’ll be replacing the author post link with an anchor to their website’s URL instead.</p>
<p>[sourcecode language="php"]</p>
<div id="authorbox">
   <?php if (function_exists('get_avatar')) { echo get_avatar(get_the_author_meta('user_email'), '80'); }?></p>
<div>
<h4>About <a href="<?php the_author_meta('user_url'); ?>&#8220;><?php the_author_meta('display_name'); ?></a></h4>
<p><?php the_author_meta('description'); ?></p>
</p></div>
</div>
<p>[/sourcecode]<br />
Even though this didn’t condense the code, it does become easier to skim through on the code end. For the most part, it’s very easy to read the tags involved.</p>
<p>Notice that in the case of our gravatar email, we’re only interested in getting the value as a string and not in displaying it. This is the something that is easy to get caught up with, and should be one of the first checks whenever you’re experiencing errors.</p>
<p><strong>Break It Down!</strong><br />
As demonstrated above, this seemingly tiny update makes it monumentally easier to pull specific information about the author and display it as you please. From here, it’s just a matter of finding new ways to break down specific components in new and creative ways.</p>
<p>Have any ideas for clever applications? Let the rest of us recently upgraded Wordpress fiends in on it too!</p>
<p><strong>Credit To :</strong> <a href="http://www.buildinternet.com">http://www.buildinternet.com</a></p>
<p><!--adsense--></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;bodytext=%0D%0AOne%20of%20the%20%28many%29%20nice%20updates%20the%20comes%20bundled%20in%20Wordpress%202.8%20is%20with%20the_author_meta%28%29%20template%20tag.%20This%20tag%20allows%20a%20developer%20to%20pull%20and%20display%20specific%20parts%20of%20any%20user%E2%80%99s%20information%20within%20a%20theme.%20Even%20though%20variations%20of%20this%20have" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;notes=%0D%0AOne%20of%20the%20%28many%29%20nice%20updates%20the%20comes%20bundled%20in%20Wordpress%202.8%20is%20with%20the_author_meta%28%29%20template%20tag.%20This%20tag%20allows%20a%20developer%20to%20pull%20and%20display%20specific%20parts%20of%20any%20user%E2%80%99s%20information%20within%20a%20theme.%20Even%20though%20variations%20of%20this%20have" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;t=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;annotation=%0D%0AOne%20of%20the%20%28many%29%20nice%20updates%20the%20comes%20bundled%20in%20Wordpress%202.8%20is%20with%20the_author_meta%28%29%20template%20tag.%20This%20tag%20allows%20a%20developer%20to%20pull%20and%20display%20specific%20parts%20of%20any%20user%E2%80%99s%20information%20within%20a%20theme.%20Even%20though%20variations%20of%20this%20have" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;headline=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=%0D%0AOne%20of%20the%20%28many%29%20nice%20updates%20the%20comes%20bundled%20in%20Wordpress%202.8%20is%20with%20the_author_meta%28%29%20template%20tag.%20This%20tag%20allows%20a%20developer%20to%20pull%20and%20display%20specific%20parts%20of%20any%20user%E2%80%99s%20information%20within%20a%20theme.%20Even%20though%20variations%20of%20this%20have" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;bm_description=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;t=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;h=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;story_title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;submitHeadline=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8&amp;submitSummary=%0D%0AOne%20of%20the%20%28many%29%20nice%20updates%20the%20comes%20bundled%20in%20Wordpress%202.8%20is%20with%20the_author_meta%28%29%20template%20tag.%20This%20tag%20allows%20a%20developer%20to%20pull%20and%20display%20specific%20parts%20of%20any%20user%E2%80%99s%20information%20within%20a%20theme.%20Even%20though%20variations%20of%20this%20have&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fphp%2Fdisplaying-author-meta-information-in-wordpress-2-8%2F&amp;title=Displaying%20Author%20Meta%20Information%20in%20Wordpress%202.8" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/php/displaying-author-meta-information-in-wordpress-2-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display Thumbnails For Related Posts in Wordpress</title>
		<link>http://www.w3updates.com/server-scripting/display-thumbnails-for-related-posts-in-wordpress/</link>
		<comments>http://www.w3updates.com/server-scripting/display-thumbnails-for-related-posts-in-wordpress/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 11:57:36 +0000</pubDate>
		<dc:creator>alyaspk</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Scripting]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[display thumbnail]]></category>
		<category><![CDATA[posts]]></category>
		<category><![CDATA[related post]]></category>
		<category><![CDATA[thumbnail]]></category>
		<category><![CDATA[thumbnail for related post in worpdpress]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress thumbnail]]></category>
		<category><![CDATA[wp thumbnail]]></category>

		<guid isPermaLink="false">http://w3updates.com/?p=258</guid>
		<description><![CDATA[In this tutorial you’ll learn how to increase pageviews by adding thumbnails to related posts using the popular YARPP plugin and Wordpress custom fields.
The Goal
Before we start, let’s take a look at the result of what we’re building:


Download the YARPP Plugin
The basis for this tutorial is the popular (and well named) plugin “Yet Another Related [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial you’ll learn how to increase pageviews by adding thumbnails to related posts using the popular YARPP plugin and Wordpress custom fields.</p>
<p><strong>The Goal</strong></p>
<p>Before we start, let’s take a look at the result of what we’re building:<br />
<img src="http://buildinternet.com/wp-content/uploads/yarpp-thumbails-result.jpg" alt="" /><br />
<span id="more-258"></span><br />
<strong>Download the YARPP Plugin</strong></p>
<p>The basis for this tutorial is the popular (and well named) plugin “Yet Another Related Post Plugin” or YARPP for short. We’ve used it on this blog right from the start, and it’s great for generating additional traffic for posts in the same subject. Thanks to the plugin’s latest update, we can now build our own template to display results.</p>
<p>Go ahead and <a href="http://mitcho.com/code/yarpp/">download the plugin</a> now if needed. If you’re installing YARPP for the first time and have questions, I’m going to refer you to the official site for more. This tutorial will start assuming that you have it up and running already.</p>
<p><strong>Create a Related Post Template File</strong></p>
<p>You’ll notice that when you install the plugin, it includes a folder of preset templates for a variety of display options. They are a great starting point for learning the ropes, but since what we’ll be doing is relatively simple we can start from scratch. Begin by creating a new file named “yarpp-template-thumbnails.php” in the root of your theme folder. This file will contain the structure of our related posts display.<br />
[sourcecode language="php"]<br />
<?php /*<br />
Post Thumbnail Template<br />
Author: Zach Dunn (www.buildinternet.com)<br />
*/<br />
?></p>
<h4 class="meta">Related Posts</h4>
<p><?php if ($related_query->have_posts()):?></p>
<ol class="related-posts">
		<?php while ($related_query->have_posts()) : $related_query->the_post(); ?></p>
<p>			<?php<br />
				//Set Default Thumbnail Image URL's<br />
				$related_thumbnail = get_post_meta($post->ID, &#8220;thumbnail_url&#8221;, $single = true);<br />
				$default_thumbnail = &#8216;default-image.jpg&#8217;;<br />
			?></p>
<li>
				<a href="<?php the_permalink() ?>&#8221; rel=&#8221;bookmark&#8221;><br />
				<?php if ($related_thumbnail != "") : ?><br />
					<img src="<?php echo $related_thumbnail; ?>&#8221; alt=&#8221;<?php the_title(); ?>&#8221; /><br />
				<?php else : ?><br />
					<img src="<?php echo $default_thumbnail; ?>&#8221; alt=&#8221;<?php the_title(); ?>&#8221; /><br />
				<?php endif; ?></p>
<p>				<?php the_title(); ?></a>
			</li>
<p>		<?php endwhile; ?>
	</ol>
<p><?php else: ?></p>
<p>No related posts found</p>
<p><?php endif; ?><br />
[/sourcecode]</p>
<p>The code above says that if related posts exist, it will go through each and display the thumbnail image URL stored in the custom field thumbnail_url which has been temporarily saved into the $related_thumbnail variable. If no URL exists there, it will display the contents of the $default_thumbnail. This check keeps posts from being stuck without thumbnail previews.</p>
<p>Feel free to tweak it as needed. This is a stripped down version meant to demonstrate the inclusion of images and text, but there’s really no limit as to how in depth your template can become.</p>
<p><strong>Insert into Single Template</strong></p>
<p>In order to make sure that our related posts show up as intended, let’s manually insert the function into the single.php using the code below. I recommend placing it somewhere under the_content() tag.<br />
[sourcecode language="php"]<br />
<?php if (function_exists('related_posts')){ ?><br />
      <?php related_posts();?><br />
<?php }?><br />
[/sourcecode]</p>
<p>Put simply, this code checks to see if the YARPP plugin is active, and shows the related posts if so.</p>
<p><strong>Customize with CSS</strong></p>
<p>To keep things simple, we’ll just stack the results so that the thumbnail displays on top and the post title on the bottom. Paste the following CSS into your theme’s stylesheet for a good starting point.<br />
[sourcecode language="css"]<br />
/* Related Posts */<br />
ol.related-posts {clear:both; text-align:center; margin:10px 0px 0px 0px; padding:0;}<br />
ol.related-posts li{width:120px; float:left; display:inline; margin-right:15px;; padding:0;}<br />
	ol.related-posts img{clear:both; padding:5px; background:#F7F7F7; border:1px solid #DDD;}<br />
	ol.related-posts a{clear:both; display:block; border:none; text-decoration:none;}<br />
	ol.related-posts li{font-size:12px;}<br />
[/sourcecode]</p>
<p><strong>Activate The New Template</strong></p>
<p>Now that you’ve built a form for YARPP to render the related posts from, you’ll have to let the plugin know that you want to use the template. This can be done from within the plugin’s option panel in the Wordpress dashboard.</p>
<p>Look for the “Display Options” section, and check the “Display using a custom template file” box. This will give you a chance to select the correct template from a dropdown box. If you’ve been following along with my naming conventions, you’ll want to pick “yarpp-template-thumbnails.php” and then save your changes.<br />
<img src="http://buildinternet.com/wp-content/uploads/yarpp-thumbnail-select-template.jpg" alt="" /></p>
<p><strong>Specifying Thumbnail in Custom Fields<br />
</strong></p>
<p>The frameworks are in place, but how do you specify what thumbnail a post will use? The solution is surprisingly simple. When you’re editing a post in Wordpress, you’ll notice a section below the write panel titled “Custom Fields.” This is where we’ll paste the URL of the thumbnail to be used for each post.<br />
<img src="http://buildinternet.com/wp-content/uploads/yarpp-thumbnail-custom-fields.jpg" alt="" /></p>
<p>Once you’ve pasted in the URL of the thumbnail image to use, update the post and then YARPP should show it when displaying related posts. No extra headache involved here.</p>
<p>Grab More Attention<br />
With image previews for each of your posts, there’s a better chance someone might see something that inspires them. To help you get started, I’ve included a ZIP file below that contains my version of the YARPP template. At the very least, it should help you get started with your own ventures.</p>
<p><strong>Download : </strong><a href="http://buildinternet.com/wp-content/uploads/related-post-thumbnails.zip">Click Here</a></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;bodytext=In%20this%20tutorial%20you%E2%80%99ll%20learn%20how%20to%20increase%20pageviews%20by%20adding%20thumbnails%20to%20related%20posts%20using%20the%20popular%20YARPP%20plugin%20and%20Wordpress%20custom%20fields.%0D%0A%0D%0AThe%20Goal%0D%0A%0D%0ABefore%20we%20start%2C%20let%E2%80%99s%20take%20a%20look%20at%20the%20result%20of%20what%20we%E2%80%99re%20building%3A%0D%0A%0D" title="Digg"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F" title="Sphinn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;notes=In%20this%20tutorial%20you%E2%80%99ll%20learn%20how%20to%20increase%20pageviews%20by%20adding%20thumbnails%20to%20related%20posts%20using%20the%20popular%20YARPP%20plugin%20and%20Wordpress%20custom%20fields.%0D%0A%0D%0AThe%20Goal%0D%0A%0D%0ABefore%20we%20start%2C%20let%E2%80%99s%20take%20a%20look%20at%20the%20result%20of%20what%20we%E2%80%99re%20building%3A%0D%0A%0D" title="del.icio.us"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;t=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="Facebook"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="Mixx"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;annotation=In%20this%20tutorial%20you%E2%80%99ll%20learn%20how%20to%20increase%20pageviews%20by%20adding%20thumbnails%20to%20related%20posts%20using%20the%20popular%20YARPP%20plugin%20and%20Wordpress%20custom%20fields.%0D%0A%0D%0AThe%20Goal%0D%0A%0D%0ABefore%20we%20start%2C%20let%E2%80%99s%20take%20a%20look%20at%20the%20result%20of%20what%20we%E2%80%99re%20building%3A%0D%0A%0D" title="Google Bookmarks"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="DZone"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" /></a>
	<a rel="nofollow"  target="_blank" href="http://cgi.fark.com/cgi/fark/farkit.pl?h=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F" title="Fark"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/fark.png" title="Fark" alt="Fark" /></a>
	<a rel="nofollow"  target="_blank" href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="Faves"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" /></a>
	<a rel="nofollow"  target="_blank" href="http://laaik.it/NewStoryCompact.aspx?uri=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;headline=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12" title="laaik.it"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/laaikit.png" title="laaik.it" alt="laaik.it" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;source=Online+Source+For+HTML%2C+XHTML%2C+CSS%2C+JavaScript%2C+AJAX%2C+XML%2C+PHP%2C+Ruby%2C+PHP+Frameworks+html+tutorials%2C+html+tips%2C+PHP%2C+SQL%2C+MySql%2C+MSSQL%2C+PHP+Tutorial%2C++html+codes%2C+XHTML%2C+CSS%2C+JS+Tutorial%2C++Learn+html%2C++Ruby+on+Rails%2C+Ajax+tutorial%2C+PHP+Frameworks+Tutorial%2C+ASP.NET%2C+W3+School%2C+W3+Validator%2C+Flash+Tutorial%2C+SEO+Tips%2C+Web+Building%2C+Server+Scripting&amp;summary=In%20this%20tutorial%20you%E2%80%99ll%20learn%20how%20to%20increase%20pageviews%20by%20adding%20thumbnails%20to%20related%20posts%20using%20the%20popular%20YARPP%20plugin%20and%20Wordpress%20custom%20fields.%0D%0A%0D%0AThe%20Goal%0D%0A%0D%0ABefore%20we%20start%2C%20let%E2%80%99s%20take%20a%20look%20at%20the%20result%20of%20what%20we%E2%80%99re%20building%3A%0D%0A%0D" title="LinkedIn"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="Live"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;bm_description=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;plugin=soc" title="MisterWong"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;t=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="MySpace"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvibes.com/share?title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F" title="Netvibes"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.netvouz.com/action/submitBookmark?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;popup=no" title="Netvouz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/netvouz.png" title="Netvouz" alt="Netvouz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;h=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="NewsVine"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.propeller.com/submit/?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F" title="Propeller"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/propeller.png" title="Propeller" alt="Propeller" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="Reddit"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F" title="Slashdot"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://socialogs.com/add_story.php?story_url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;story_title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="Socialogs"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/socialogs.png" title="Socialogs" alt="Socialogs" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="StumbleUpon"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F" title="Technorati"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress%20-%20http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F" title="Twitter"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;submitHeadline=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress&amp;submitSummary=In%20this%20tutorial%20you%E2%80%99ll%20learn%20how%20to%20increase%20pageviews%20by%20adding%20thumbnails%20to%20related%20posts%20using%20the%20popular%20YARPP%20plugin%20and%20Wordpress%20custom%20fields.%0D%0A%0D%0AThe%20Goal%0D%0A%0D%0ABefore%20we%20start%2C%20let%E2%80%99s%20take%20a%20look%20at%20the%20result%20of%20what%20we%E2%80%99re%20building%3A%0D%0A%0D&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.diigo.com/post?url=http%3A%2F%2Fwww.w3updates.com%2Fserver-scripting%2Fdisplay-thumbnails-for-related-posts-in-wordpress%2F&amp;title=Display%20Thumbnails%20For%20Related%20Posts%20in%20Wordpress" title="Diigo"><img src="http://www.w3updates.com/wp-content/plugins/sociable/images/diigo.png" title="Diigo" alt="Diigo" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.w3updates.com/server-scripting/display-thumbnails-for-related-posts-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
