<?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>Not A n00b &#187; tutorial</title>
	<atom:link href="http://notan00b.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://notan00b.com</link>
	<description>Tutorials, Scripts, and Rants</description>
	<lastBuildDate>Wed, 12 May 2010 08:08:35 +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>PHP to create website thumbnails</title>
		<link>http://notan00b.com/2009/09/php-to-create-website-thumbnails/</link>
		<comments>http://notan00b.com/2009/09/php-to-create-website-thumbnails/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 00:46:20 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[explorer]]></category>
		<category><![CDATA[frontpage]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[internetexplorer]]></category>
		<category><![CDATA[internetexplorer.application]]></category>
		<category><![CDATA[nails]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[shot]]></category>
		<category><![CDATA[thumb]]></category>
		<category><![CDATA[thumbnails]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webpage]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=230</guid>
		<description><![CDATA[Want to know how to create a thumbnail/screen shot of a webpage using PHP?  Well check it out here]]></description>
			<content:encoded><![CDATA[<p>Bing.com has an awesome feature that is popping up more and more all over the internet.  Most websites charge for this, as they should.  It isn&#8217;t something that can be done on a normal hosting plan, but can only be done (this way) on a Windows server, where Internet Explorer is installed and you have access to.  There are several ways to do this on Linux servers, but I am going to cover the Windows version.</p>
<p>In order to create an image for a thumbnail, we need to take a screen shot of webpage.  PHP GD class allows us to take screen shots of different windows.  PHP also allows us to control different windows, like Internet Explorer using the COM class.  So basically what we need to do is have PHP open up a window in Internet Explorer, navigate to a website, and then take a picture of that window, then save it/display it.  The tutorial shown on php.net shows exactly how to do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InternetExplorer.Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HWND</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Visible</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.libgd.org&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Still working? */</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Busy</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">com_message_pump</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagegrabwindow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Quit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;iesnap.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>So this is SUPPOSED to load libgd.org and take a snap shot and save it to &#8220;iesnap.png&#8221;, and it DOES work, but only if your server allows it to work.  If it doesn&#8217;t you just get a black/blank picture.  </p>
<p>Windows rarely lets one program access another program via the desktop and control it.  By default, Apache isn&#8217;t allowed to open Internet Explorer on windows, so we have to add an exception.  </p>
<ol>
<li>On Vista, click the start button, and in the search box type &#8220;Services&#8221;.  </li>
<li>At the very top, there should be a link under Programs called Services.  Click that link. </li>
<li>It will open up all running services, and you will see Apache running (mine is Apache 2.2, and is the first entry).</li>
<li>Right click on it and select &#8220;Properties&#8221;</li>
<li>Navigate to the &#8220;Log On&#8221; tab</li>
<li>Click the box for &#8220;Allow service to interact with the desktop&#8221;</li>
<li>Save it and close the properties</li>
<li>Right click on Apache again</li>
<li>This time, click restart, and Apache will be restarted with the new features</li>
</ol>
<p>Now run your script again!  Vista pops up a little box alerting the user that a program is interact with the desktop.  Just ignore it and it will disappear in a few seconds.  After the program is complete, go to your web folder and you will see iesnap.png is now an image of a webpage!</p>
<p>Time to make some tweaks!  You will notice that it grabs the ENTIRE screen, meaning the tool bars and everything.  We will need to make a few adjustments to get rid of those.  The first one I made was to make the browser show as a full screen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InternetExplorer.Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HWND</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Visible</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FullScreen</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

<p>That last line will make it display in the fullscreen mode, which takes care of the tool bars at the top, but I still see the footer and the side bar that I want to get rid of.  In order to do this, we need to crop a little, but GD doesn&#8217;t have a simple cropping method.  What I did was copied part of this picture to a new picture and resized it.  Keep in mind, my display settings are going to be different, and will require you to look at your picture and test it out:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$w</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$h</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$url</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;www.notan00b.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1263</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$w</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1263</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">780</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$h</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1263</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;InternetExplorer.Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HWND</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Visible</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FullScreen</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/* Still working?*/</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Busy</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">com_message_pump</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagegrabwindow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Quit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;iesnap.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Copy</span>
<span style="color: #990000;">imagecopyresized</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest</span><span style="color: #339933;">,</span> <span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$h</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1263</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">780</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output and free from memory</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>There we have it.  Even with the GET variables so you can reuse this script for AJAX or any HTML document.  My images were 1280&#215;800.  To remove the bars I scaled it down to 1263&#215;780, and they were removed almost perfectly, but it will be different for everyone.</p>
<p>I would post an example of it, but I am only hosted&#8230; I don&#8217;t actually pay for a VPS or private server just for one little blog.  Sorry folks.  If it was up to me, and I needed this service, I would probably pay a company to do it for me for a simple little website.  If you have a VPS with enough memory, this may work for you.  Good luck, let me know if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/09/php-to-create-website-thumbnails/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WhosOnline Tutorial now online!</title>
		<link>http://notan00b.com/2009/09/whosonline-tutorial-now-online/</link>
		<comments>http://notan00b.com/2009/09/whosonline-tutorial-now-online/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 21:19:53 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[whosonline]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=227</guid>
		<description><![CDATA[With the success of the WhosOnline PHP script, I have made a quick and simple tutorial on how to use it for whatever you decide.  It is really easy and can be used to do anything from displaying the total number of people online, to displaying all the members names individually.  Take a [...]]]></description>
			<content:encoded><![CDATA[<p>With the success of the WhosOnline PHP script, I have made a quick and simple tutorial on how to use it for whatever you decide.  It is really easy and can be used to do anything from displaying the total number of people online, to displaying all the members names individually.  <a href="http://notan00b.com/tutorials/">Take a look at it in the Tutorials section!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/09/whosonline-tutorial-now-online/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial [Part 2] underway!</title>
		<link>http://notan00b.com/2009/08/php-tutorial-part-2-underway/</link>
		<comments>http://notan00b.com/2009/08/php-tutorial-part-2-underway/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 20:08:21 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[2]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[part]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=201</guid>
		<description><![CDATA[Its been a while since I got an update up.  I started working on the second part of my PHP tutorial.  I plan on covering functions, arrays, and get/post variables for now.  I will probably have a third part eventually covering advanced topics like classes, sessions, cookies, files, mysql, and stuff like [...]]]></description>
			<content:encoded><![CDATA[<p>Its been a while since I got an update up.  I started working on the second part of my PHP tutorial.  I plan on covering functions, arrays, and get/post variables for now.  I will probably have a third part eventually covering advanced topics like classes, sessions, cookies, files, mysql, and stuff like that.  For now though, I am going to finish the basics.  I posted the first draft in the tutorial section.  I will update it for the next couple days until I get it completed to my satisfaction.  Check it out!</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/08/php-tutorial-part-2-underway/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Database Tutorial posted!</title>
		<link>http://notan00b.com/2009/08/wordpress-database-tutorial-posted/</link>
		<comments>http://notan00b.com/2009/08/wordpress-database-tutorial-posted/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 19:18:37 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[creation]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wp-db.php]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=190</guid>
		<description><![CDATA[I just created an in depth tutorial that covers the entire wp-db.php file and how WordPress uses it, and how to use it to create plug-ins for WordPress.  It is posted in the tutorials section, here.  Check it out and let me know what you think.
]]></description>
			<content:encoded><![CDATA[<p>I just created an in depth tutorial that covers the entire wp-db.php file and how WordPress uses it, and how to use it to create plug-ins for WordPress.  It is posted in the tutorials section, <a href="http://notan00b.com/tutorials/">here</a>.  Check it out and let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/08/wordpress-database-tutorial-posted/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>More with PHP Classes</title>
		<link>http://notan00b.com/2009/08/more-with-php-classes/</link>
		<comments>http://notan00b.com/2009/08/more-with-php-classes/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 20:13:19 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[employee]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=184</guid>
		<description><![CDATA[I got a comment on my PHP OOP tutorial to explain how to relate what I taught to real life scenarios.  His scenario was Human Resources Information.  The first thing we will need to decide is what info is important, so lets list a few items:

First name
Last Name
Social Security Number
Address
City
State
Zip
Date of birth
Salary
Position
Start Date

That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I got a comment on my PHP OOP tutorial to explain how to relate what I taught to real life scenarios.  His scenario was Human Resources Information.  The first thing we will need to decide is what info is important, so lets list a few items:</p>
<ul>
<li>First name</li>
<li>Last Name</li>
<li>Social Security Number</li>
<li>Address</li>
<li>City</li>
<li>State</li>
<li>Zip</li>
<li>Date of birth</li>
<li>Salary</li>
<li>Position</li>
<li>Start Date</li>
</ul>
<p>That&#8217;s probably sufficient for our purposes, and then some.  So the next question we need to ask is, what are we planning on doing with this info?  I would assume a lot of it would be interacting with a database.  This would probably involve a lot of CRUD operations (Create, Read, Update, Delete).  So we need to make functions for each.  One to create a new employee in the database, one to get employee info, one to update employee info if it is changed, one to delete employees once they have been fired or never completed training or whatever.  The one other thing I can think of is maybe assigning an employee an ID so he can easily be tracked in the system, in case there are two Mr. John Smith employees.  Speaking of searching, maybe a search function would be nice as well.  So lets set out to create our class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Employee
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$Id</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$FirstName</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$LastName</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$DOB</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$Position</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$Salary</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$StartDate</span><span style="color: #339933;">=</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m/d/Y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$EndDate</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">function</span> _construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">!=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LoadEmployee</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> LoadEmployee<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">/*** Connect to database  ***/</span>
        <span style="color: #666666; font-style: italic;">/*** Code Not Included ***/</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT FROM Employees WHERE Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//makes sure the user exists</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//Sets class variables</span>
            <span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Id</span><span style="color: #339933;">=</span><span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FirstName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'LastName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOB'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Position</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Position'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Salary'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">StartDate</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'StartDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EndDate</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'EndDate'</span><span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> CreateEmployee<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CheckVariables</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">/*** Connect to database  ***/</span>
        <span style="color: #666666; font-style: italic;">/*** Code Not Included ***/</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;INSERT INTO Employees (FirstName,LastName,DOB,Position,Salary,StartDate) VALUES ('&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">StartDate</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;')&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//Inserted, and now lets return his ID number</span>
        <span style="color: #000088;">$query2</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT Id FROM Employees WHERE FirstName='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' AND LastName='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' AND DOB='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' AND StartDate='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">StartDate</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>      
    <span style="color: #000000; font-weight: bold;">function</span> CheckVariables<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//makes sure we don't have any empty variables in the areas that matter</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>empty<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>empty<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>empty<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Position</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>empty<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">else</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> UpdateEmployee<span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//makes sure an ID is chosen or specified.</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">==</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">/*** Connect to database  ***/</span>
        <span style="color: #666666; font-style: italic;">/*** Code Not Included ***/</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UPDATE Employees SET <span style="color: #006699; font-weight: bold;">$field</span>='<span style="color: #006699; font-weight: bold;">$value</span>' WHERE Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> ToArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Id</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FirstName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'LastName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Position'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Position</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Salary'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOB'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'StartDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">StartDate</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'EndDate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EndDate</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$array</span><span style="color: #339933;">;</span>        
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Here is the finished class minus a few things that you can add if you want.  What my class does is creates employees, updates specific fields, checks information, turns the info into an array, etc.  I didn&#8217;t include all the variables we listed because I am lazy, as well as the delete function.  There are always improvements that can be made, but this is a good starting block for any programmer.  So lets see how we use it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;classEmployee.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//create a new employee</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FirstName</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Bob&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LastName</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Smith&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DOB</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;01/01/99&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Position</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Data Entry&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Salary</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$10</span>/hr&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$empid</span><span style="color: #339933;">=</span><span style="color: #000088;">$emp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateEmployee</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//And now he was created and entered into the system.</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$empid</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//His ID;</span>
<span style="color: #666666; font-style: italic;">//lets check to make sure he is still in the system.</span>
<span style="color: #000088;">$emp2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #009900;">&#40;</span><span style="color: #000088;">$empid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$empArray</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$emp2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ToArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$empArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//ok, all looks good.  Lets update his name.</span>
<span style="color: #000088;">$emp2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">UpdateEmployee</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;FirstName&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Bobby&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$empid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Well that&#8217;s my sample.  Its pure rough draft, and probably won&#8217;t even work properly, but I am conveying the IDEA of OOP and employees.  Think how much smoother your code would be if you created a few forms asking for employees IDs and it loads it, or allows the HR Department to enter a new employees info straight into the database on a very simple form.  Good luck with this!  Let me know if there are any other problems I can help with!</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/08/more-with-php-classes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP PDO and SQL injections</title>
		<link>http://notan00b.com/2009/08/php-pdo-and-sql-injections/</link>
		<comments>http://notan00b.com/2009/08/php-pdo-and-sql-injections/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 18:22:42 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bypass]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[injections]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[MsSQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=179</guid>
		<description><![CDATA[SQL Injections o_O???]]></description>
			<content:encoded><![CDATA[<p>MySQL and MsSQL are huge when it comes to internet sites.  They are probably the easiest databases to set up and the most universal when it comes to internet apps.  The only problem is that programmers are sometimes lazy and forget to think about things like security when it comes to programming the forms and site.  When people are lazy, they leave their sites open to SQL injections.  I don&#8217;t really want to make this an SQL injection tutorial, but just want to touch on it briefly.  Lets start with a standard SQL statement that a form uses to find an Administrator password:<br />
<code>mysql&gt; SELECT * FROM Users WHERE Name='Admin' AND Pass='MyP4ssw0rd';</code><br />
Now if we add a login form and use php, we might have code structured similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$name</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT * FROM Users WHERE Name='<span style="color: #006699; font-weight: bold;">$name</span>' AND Pass='<span style="color: #006699; font-weight: bold;">$pass</span>'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This would work perfectly, and would allow people to log in.  It would also allow people to SQL inject it.  What if they typed this in:</p>
<table>
<tr>
<td>Name:</td>
<td>
<input type="text" value="admin"></td>
</tr>
<tr>
<td>Pass:</td>
<td>
<input type="text" value="admin' OR 'x'='x"></td>
</tr>
</table>
<p>
Well our SQL statement ends up looking like this:<br />
<code>SELECT * FROM Users WHERE Name='admin' AND Pass='admin' OR 'x'='x'</code><br />
&#8216;x&#8217;='x&#8217; is a TRUE statement 100% of the time, so as long as &#8216;x&#8217;='x&#8217;, it will pull up all the info you needed, and suddenly you are logged in.  This is probably the easiest SQL injection around, and does work on occasion.  There are hundreds of SQL injections, and a poorly coded site will always be susceptible.  Not only are people able to log into a site as an administrator, but they can display login info using UNION statements.<br />
One other way good programmers tend to get lazy is through their &#8220;GET&#8221; variables.  A lot of times programmers will pass variables in the URL bar: http://www.mysite.com/view.php?id=123.  There is nothing wrong with this, in fact, everyone does it and will continue to do it because it is efficient and easy to do.  The problem comes when people SQL inject that variable: view.php?id=123&#8242; and &#8216;x&#8217;='y.  This particular injection allows a hacker to test your site for susceptibility to injections in the URL bar.  If you didn&#8217;t protect your variables, your SQL statement would look like this if it wasn&#8217;t protected: <code>"SELECT * FROM Info WHERE Id='123' and 'x'='y'"</code>.  If it wasn&#8217;t protected, the hacker would see a page with NO info on it, or an error because &#8216;x&#8217; NEVER equals &#8216;y&#8217; and is a FALSE statement.  If they see a blank page or an error, they know they can continue their attack and eventually gain access to all of your information.</p>
<p>My goal is not to teach you how to hack, but rather how a simple PHP object exists and will help you avoid these types of attacks.  That object is PDO.  It comes standard with the latest releases of PHP and can be used to prevent SQL injections very simply.  PDO is a database object, that allows you to connect to a variety of different databases, send queries, and display the results.  It actually is a bit easier to code than actual mysql in PHP, but it is a complete 180 from what you have been taught using w3schools and tizag.com.  I don&#8217;t really want to get into a tutorial of PDO either because there are quite a few on the internet that explain it much better than I can right now.  I recommend checking out <a href="http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html">http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html</a> to get a grip on the basics of how PDO works.  The one thing that this tutorial does NOT explain is the &#8220;prepare&#8221; function.  He only goes into it slightly, but doesn&#8217;t describe what it does exactly.  Prepare() simply checks for all types of quotes and makes sure that no SQL injections can get through.  Here is a quick example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$mysql_host</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_user</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_pass</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_database</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;epco&quot;</span><span style="color: #339933;">;</span>
try <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mysql:host=<span style="color: #006699; font-weight: bold;">$mysql_host</span>;dbname=<span style="color: #006699; font-weight: bold;">$mysql_database</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** create the statement ***/</span>
    <span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM users WHERE user = :user AND pass = :pass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** bind the paramaters ***/</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':user'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_STR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':pass'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_STR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** execute the prepared statement ***/</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** close the database connection ***/</span>
    <span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>    
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>PDOException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>When we prepare our statement, we use a place-holder that will later assign a variable to.  When that statement is executed, all our quotes are removed or slashed.  <code>$_POST['user']="admin' OR 1=1";</code> typically becomes <code>$_POST['user']="admin\' OR 1=1";</code> and your database is protected from the attacks.</p>
<p>In conclusion, I am not advocating PDO and saying only to use that and nothing else.  I use a database class that is much smaller and does what I need it to do.  I have spoken with other programmers who have created their own class to add/strip slashes, rawurlencode/decode, and htmlspecialcharacters and connect to their databases.  PDO was created as a &#8220;universal&#8221; database object that can do whatever you want it to do with several different databases.  It is awesome and will go a long way to protect your site from SQL injections if used properly.  The prepare statement is simple, but doesn&#8217;t protect against EVERY type of attack.  Don&#8217;t be fooled into a false sense of security just because you are using a PHP object.  XSS, javascript injections, and bruteforce, attacks are all still possible even if you use this class.  Be careful in what you code, and fix any code when the holes are found by users or when you are hacked.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/08/php-pdo-and-sql-injections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wordpress page views hack</title>
		<link>http://notan00b.com/2009/07/wordpress-page-views-hack/</link>
		<comments>http://notan00b.com/2009/07/wordpress-page-views-hack/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 19:54:22 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[counter]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=177</guid>
		<description><![CDATA[I created this pretty quick, and it is by far, not the prettiest thing out there.  This uses an extra table in the MySQL table to keep track of pages that get viewed and how many times they are viewed.  Here is what I did:
Step 1 &#8211; Create a new table!
Go to your [...]]]></description>
			<content:encoded><![CDATA[<p>I created this pretty quick, and it is by far, not the prettiest thing out there.  This uses an extra table in the MySQL table to keep track of pages that get viewed and how many times they are viewed.  Here is what I did:</p>
<p><b>Step 1 &#8211; Create a new table!</b><br />
Go to your MySQL database and create a table called &#8220;wp_counter&#8221; with 2 fields: Post_Id and Count.  Both are Int with length 10.  Here is the SQL code you can copy and paste to make it a bit shorter:<br />
<code>CREATE TABLE `wp_counter` (`Post_Id` INT( 10 ) NOT NULL , `Count` INT( 10 ) NOT NULL) </code></p>
<p><b>Step 2 &#8211; Editing post-template.php</b><br />
This is the file that is used to display your posts (not the snippets on your front page, but full out posts).  It is located in the &#8220;wp-includes&#8221; directory.<br />
Open post-template.php for editing.<br />
Search for a function called &#8220;<code>the_content()</code>&#8220;.  It typically starts on line 165 should look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>165
166
167
168
169
170
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> get_the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So what we want to do is make it so that every time it shows the content, it will update the count and display it to the user.  So we are going to change that function to look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>165
166
167
168
169
170
171
172
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> get_the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
	update_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span><span style="color: #0000ff;">&quot;&lt;small&gt;&lt;i&gt;Views: &quot;</span><span style="color: #339933;">.</span>get_content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/i&gt;&lt;/small&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And immediately following that, we are going to add a couple functions:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> update_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wp_counter&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post_Id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Count'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$count</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_counter'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Count'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post_Id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s it!  So your finalized post-template.php will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> get_the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
	update_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span><span style="color: #0000ff;">&quot;&lt;small&gt;&lt;i&gt;Views: &quot;</span><span style="color: #339933;">.</span>get_content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/i&gt;&lt;/small&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> update_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wp_counter&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post_Id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Count'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$count</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_counter'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Count'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post_Id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> get_content_views<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM wp_counter WHERE Post_Id='<span style="color: #006699; font-weight: bold;">$id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now every time someone visits the page, they will see how many other people have viewed that page!</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/wordpress-page-views-hack/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>jQuery tutorial has been posted.</title>
		<link>http://notan00b.com/2009/07/jquery-tutorial-has-been-posted/</link>
		<comments>http://notan00b.com/2009/07/jquery-tutorial-has-been-posted/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 01:54:03 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=143</guid>
		<description><![CDATA[This is a simple tutorial, designed mostly just to introduce you to jQuery.  If you have had some experience with Javascript, you should be able to pick this up very quickly after reading through the tutorial.  I provide the structure and a couple examples.  If anyone needs help with a script or [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple tutorial, designed mostly just to introduce you to jQuery.  If you have had some experience with Javascript, you should be able to pick this up very quickly after reading through the tutorial.  I provide the structure and a couple examples.  If anyone needs help with a script or is having problems getting it working, post a comment and I will help out as best I can.  <a href="/tutorials/">Check out the page!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/jquery-tutorial-has-been-posted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery &#8211; Lesson 2</title>
		<link>http://notan00b.com/2009/07/jquery-lesson-2/</link>
		<comments>http://notan00b.com/2009/07/jquery-lesson-2/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 00:05:25 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[child]]></category>
		<category><![CDATA[click]]></category>
		<category><![CDATA[each]]></category>
		<category><![CDATA[hover]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sibling]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=125</guid>
		<description><![CDATA[I have been working pretty intensely with jQuery and have learned a lot.  It is a difficult language to work with because it is picky.  But once you understand it, it is actually quite simple to manipulate.
Today I want to cover parent/child/sibling relationships and how jQuery can be very effective here.  I [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working pretty intensely with jQuery and have learned a lot.  It is a difficult language to work with because it is picky.  But once you understand it, it is actually quite simple to manipulate.</p>
<p>Today I want to cover parent/child/sibling relationships and how jQuery can be very effective here.  I spent a while trying to figure this out in javascript, and yes, it is completely do-able in just a little more code, but jQuery always has the UI plugins that make coding super easy.  Let me show you some code I currently have:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
   <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#rows'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span>
         <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rows-add-class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
         <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rows-add-class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.section2, .section3, .section4, .section5'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;viewClient.php?id=&quot;</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.section1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'checked'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'checked'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">else</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'checked'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I know this looks complicated, but lets break it down line by line.</p>
<ol>
<li><code>$('div').each(function (){</code></li>
<p>This code goes through each &lt;div&gt; in my code, and with each &lt;div&gt; it finds, it executes a function, which is the remainder of the code.</p>
<li><code>if($(this).is('#rows')) {</code></li>
<p>So when it finds a
<div>, it checks to see if the &lt;div&gt; that was found &#8220;is&#8221; (or has the property of) &#8216;#rows&#8217;.  The # in the front means the &lt;div&gt; id.  If there is a &#8220;.&#8221; in front, it means the &lt;div&gt; class.  If there is nothing, then it means that it is a tag itself.  So when it finds the div tag with the id=&#8221;rows&#8221;, it will execute the following code.</p>
<li><code>$(this).hover(</code></li>
<p>Simply, it adds a hover class to the div with the id=&#8221;rows&#8221;.  When you add a hover, you need to have it do 2 things, mouseover and mouseout.  So the next parts of the code describe mouseover and mouseout respectively.</p>
<li><code>function() { $(this).addClass('rows-add-class'); },</code></li>
<p>So on mouseover, it will execute this function, which is, it will add a class called &#8216;rows-add-class&#8217; to the div we have selected.  Note the &#8220;,&#8221; at the end, which means that this is the next line is also part of hover().</p>
<li><code>function() { $(this).removeClass('rows-add-class'); }</code></li>
<p>On mouseout, it will remove the class.  We could have it add another class or give us an alert if we wanted, but typically when you hover over something with the mouse, you want to emphasize/change something, and when you move it out, you want it to return to normal.</p>
<li><code>);</code></li>
<p>So finally we start closing stuff up.  This closes up the hover statement.</p>
<li><code>$(this).children('.section2, .section3, .section4, .section5').click(function(){</code></li>
<p>Here we are getting into children.  If you have a div, and inside that div, you have multiple other divs, you may want to do something to those divs.  What I am doing here is adding an &#8220;onclick&#8221; function to the children divs with classes &#8220;section2&#8243;, &#8220;section3&#8243;, &#8220;section4&#8243;, &#8220;section5&#8243;.  Notice how here I used &#8216;.section1, etc&#8217;, the &#8220;.&#8221; signifies classes.  So this is statement, I am adding an &#8220;onclick&#8221; to the child tags under &#038;ltldiv id=&#8221;rows&#8221;&gt;.  The next line will tell me what exactly I am going to do when I click on one of those 4 child divs.</p>
<li><code>window.location.href= "viewClient.php?id="+$(this).siblings('.small').children('#cb').val();</code></li>
<p>Wow, thats a long line of code!  window.location.href= is a redirect, so basically, when you click the divs, it will act like a link and take you somewhere else.  It looks like it will take you to a viewClient.php page with the id= whatever $(this).siblings(&#8216;.small&#8217;).children(&#8216;#cb&#8217;).val(); equals.  It gets a little confusing here.  So &lt;div id=&#8221;rows&#8221;&gt; is set up with a few children tags, and those children have a few tags.  All of the children are siblings.  So if I was to click on one of the children, say one with the class &#8220;section2&#8243;, I want to find out info about his sibling, with the class &#8220;small&#8221;.  Now &#8220;small&#8221; has a child with the id=&#8221;cb&#8221;.  Cb stands for check box.  Basically, when you click on the div, it will find its sibling&#8217;s, child&#8217;s value, which is the ID # we are looking for.  At the bottom of the page you can see the layout of the div with children and grandchildren.  So to recap, this line redirects us to &#8220;viewClient.php?id=1&#8243;.<br />
Why did I do this?  Well I am pulling data out of a database, and I don&#8217;t want to make a link in every div so they have to click on the words to be redirected.  These couple lines of code make it much easier for the user to redirect to the page they want.</p>
<li><code>});</code></li>
<p>Just closing up the &#8220;onclick&#8221; that we added to those 4 divs.</p>
<li><code>$(this).children('.section1').click(function(){</code></li>
<p>Here is the div with class=&#8221;section1&#8243; and we are adding a different &#8220;onclick&#8221; function to it.  Let&#8217;s see what we want it to do.</p>
<li><code>if($(this).siblings('.small').children('#cb').attr('checked'))</code></li>
<p>This looks similar to line 8 where we locate the sibling with the class=&#8221;small&#8221; and the child it has with the id=&#8221;cb&#8221;.  So we are locating our checkbox.  If our checkbox is checked (.attr(&#8216;checked&#8217;) returns true if checked, false if not checked), we are going to do something.  That was pretty easy now that siblings and children make a little sense.</p>
<li><code>$(this).siblings('.small').children('#cb').attr('checked',false);</code></li>
<p>Ok, so if it was checked, all this will do is set &#8216;checked&#8217; to false, meaning it will un-check the check box.  </p>
<li><code>else</code></li>
<p>If it wasn&#8217;t checked, then what.</p>
<li><code>$(this).siblings('.small').children('#cb').attr('checked',true);</code></li>
<p>Well then, check it!  So why did I add this code?  Well just to add it really.  It makes clicking the check box slightly easier.  They can click on this div, and it will check/uncheck the checkbox for them.
</ol>
<p>The rest of the code simply closes up the function that I created.  This is something I would have it do on start up, rather than allowing the user to click a button to enable these features.</p>
<p>This is the HTML markup that was used in the code.  The classes are easily created and is something you can do on your own.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;rows&quot;&gt;
   &lt;div class=&quot;small&quot;&gt;&lt;input type=&quot;checkbox&quot; id=&quot;cb&quot; value=&quot;1&quot;&gt;&lt;/div&gt;
   &lt;div class=&quot;section1&quot;&gt;1 (Clients ID)&lt;/div&gt;
   &lt;div class=&quot;section2&quot;&gt;Bob (Clients Name)&lt;/div&gt;
   &lt;div class=&quot;section3&quot;&gt;123 Fast Lane (Clients Address)&lt;/div&gt;
   &lt;div class=&quot;section4&quot;&gt;12345 (Clients Zip)&lt;/div&gt;
   &lt;div class=&quot;section5&quot;&gt;(123)555-1212 (Clients Phone)&lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>Pretty simple layout causes pretty intense code.  Hopefully my explanation shows you some of what jQuery can do for you and provides a plan of attack for you.  If you want any help, let me know and I will be willing to explain something, review your code, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/jquery-lesson-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial Part 1 Complete</title>
		<link>http://notan00b.com/2009/07/php-tutorial-part-1-complete/</link>
		<comments>http://notan00b.com/2009/07/php-tutorial-part-1-complete/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 06:07:23 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[1]]></category>
		<category><![CDATA[complete]]></category>
		<category><![CDATA[part]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=123</guid>
		<description><![CDATA[I have completed Part 1 for the PHP tutorial.  It can be found here.  It covers the very basics.  I will write a page on each of the basics in the future to go more in depth, and covering advanced topics.  I am planning a part 2 to cover functions, arrays, [...]]]></description>
			<content:encoded><![CDATA[<p>I have completed Part 1 for the PHP tutorial.  It can be found <a href="http://notan00b.com/php-tutorial-part-1/">here</a>.  It covers the very basics.  I will write a page on each of the basics in the future to go more in depth, and covering advanced topics.  I am planning a part 2 to cover functions, arrays, strings, mysql, files, and other topics, but it is a lot to cover.  If there are any topics you would specifically like covered, let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/php-tutorial-part-1-complete/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
