<?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>The Tutorial Blog &#187; Text Tutorials</title>
	<atom:link href="http://www.thetutorialblog.com/category/text-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thetutorialblog.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 Nov 2011 19:21:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
<link>http://www.thetutorialblog.com</link>
<url>http://www.thetutorialblog.com/wp-content/plugins/maxblogpress-favicon/icons/favicon-28.ico</url>
<title>The Tutorial Blog</title>
</image>
		<item>
		<title>Creating a basic iPad application</title>
		<link>http://www.thetutorialblog.com/cocoa-objective-c/creating-a-basic-ipad-application/</link>
		<comments>http://www.thetutorialblog.com/cocoa-objective-c/creating-a-basic-ipad-application/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 18:47:44 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[basic tutorial]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[create a basic iPad application]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[ipad app]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[UIKit]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=287</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	Because of the recent announcement of the iPad 2 more people are going to want to learn how to develop for the iPhone OS. I recently purchased an iPad 2 3G with o2, so far the broadband has been flawless. This tutorial will be a basic walk-through for beginners who want to start developing. The [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fcocoa-objective-c%2Fcreating-a-basic-ipad-application%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fcocoa-objective-c%2Fcreating-a-basic-ipad-application%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Creating a basic iPad application" alt=" Creating a basic iPad application" /><br />
			</a>
		</div>
<p><img class="alignleft size-full wp-image-292" title="ipad" src="http://www.thetutorialblog.com/wp-content/uploads/2010/02/ipad.jpg" alt="ipad Creating a basic iPad application" width="450" height="338" /><br />
Because of the recent announcement of the <a href="http://www.apple.com/ipad/">iPad 2</a> more people are going to want to learn how to develop for the <a href="http://en.wikipedia.org/wiki/IPhone_OS">iPhone OS</a>. I recently purchased an iPad 2 3G with <a href="http://www.o2.co.uk/">o2</a>, so far the broadband has been flawless.</p>
<p>This tutorial will be a basic walk-through for beginners who want to start developing.</p>
<p>The application that we will be creating will consist of two button and one label.<br />
<span id="more-287"></span></p>
<h2>Create a new project</h2>
<p>First of all open Xcode and click "Create a new Xcode project". Select View-based Application and then iPad as the product.<br />
<img class="alignleft size-full wp-image-288" title="screenshot1" src="http://www.thetutorialblog.com/wp-content/uploads/2010/02/screenshot1.jpg" alt="screenshot1 Creating a basic iPad application" width="650" height="499" /></p>
<p>Save the project as Tutorial.</p>
<h2>Outlets and Actions</h2>
<p>For things such as labels and textfields we use IBOutlets and for buttons we use IBActions. IB stands for Interface Builder and is what we will use to create our interface and link the connections.</p>
<p>To add our outlets and actions open up TutorialViewController.h.</p>
<p>Under @interface TutorialViewController : UIViewController { add:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">IBOutlet UILabel <span style="color: #339933;">*</span>currentNumber<span style="color: #339933;">;</span></pre></div></div>

<p>Then before @end add:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span>incrementNumber<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>sender<span style="color: #339933;">;</span>
<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span>decrementNumber<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>sender<span style="color: #339933;">;</span></pre></div></div>

<p>Save TutorialViewController.h.</p>
<h2>Create the interface and make connections</h2>
<p>Open up TutorialViewController.xib. From the library drag one labels and two buttons.<br />
<img class="alignleft size-full wp-image-289" title="screenshot2" src="http://www.thetutorialblog.com/wp-content/uploads/2010/02/screenshot2.jpg" alt="screenshot2 Creating a basic iPad application" width="650" height="510" /></p>
<p>Control + click the File's Owner object and drag it to the label then select currentNumber; now go from the minus and plus button to the File's Owner object and select decrementNumber for the minus button and incrementNumber for the plus button.<br />
<img class="alignleft size-full wp-image-290" title="screenshot3" src="http://www.thetutorialblog.com/wp-content/uploads/2010/02/screenshot3.jpg" alt="screenshot3 Creating a basic iPad application" width="650" height="432" /></p>
<p>Save TutorialViewController.xib and close Interface Builder.</p>
<h2>The Code</h2>
<p>Open TutorialViewController.m. Below the implementation we need to create an integer called number and set the value to 0.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> number <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span></pre></div></div>

<p>We now need to create methods for when the increment and decrement buttons are pressed.<br />
When the increment button is pressed we will increment the number integer by 1 then set the value of currentNumber to number by using a formatted string.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span>incrementNumber<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>sender <span style="color: #009900;">&#123;</span>
	number<span style="color: #339933;">++;</span>
	<span style="color: #009900;">&#91;</span>currentNumber setText<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>NSString stringWithFormat<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,</span> number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>and for decrement its the same but we decrement the number integer by 1.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span>decrementNumber<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>sender <span style="color: #009900;">&#123;</span>
	number<span style="color: #339933;">-;</span>
	<span style="color: #009900;">&#91;</span>currentNumber setText<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>NSString stringWithFormat<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,</span> number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Build and Run</h2>
<p>Press the Build and Run button (command + return) and your app will compile then open.<br />
<img class="alignleft size-full wp-image-291" title="screenshot4" src="http://www.thetutorialblog.com/wp-content/uploads/2010/02/screenshot4.jpg" alt="screenshot4 Creating a basic iPad application" width="650" height="503" /></p>
<h2>Download</h2>
<p><a href="http://bit.ly/9Kqaok">Download</a></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/cocoa-objective-c/creating-a-basic-ipad-application/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Build a Twitter-like site with CodeIgniter and jQuery Part 2</title>
		<link>http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery-part-2/</link>
		<comments>http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery-part-2/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 19:58:15 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[build a social network]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[code igniter]]></category>
		<category><![CDATA[codeigniter series]]></category>
		<category><![CDATA[codeigniter tutorial]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[how to build a social network]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery series]]></category>
		<category><![CDATA[jquery tutorial]]></category>
		<category><![CDATA[php series]]></category>
		<category><![CDATA[series]]></category>
		<category><![CDATA[the tutorial blog]]></category>
		<category><![CDATA[twitter series]]></category>
		<category><![CDATA[twitter tutorial]]></category>
		<category><![CDATA[twitter-like tutorial]]></category>
		<category><![CDATA[wez pyke]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=268</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	Don't forget to check out part 1 if you have no read it. In the second part of this 5 part tutorial series on how to build a Twitter-like website, we will be creating a signup form so that users can register to our website. We will be adding records to the database that we [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fbuild-a-twitter-like-site-with-codeigniter-and-jquery-part-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fbuild-a-twitter-like-site-with-codeigniter-and-jquery-part-2%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Build a Twitter like site with CodeIgniter and jQuery Part 2" alt=" Build a Twitter like site with CodeIgniter and jQuery Part 2" /><br />
			</a>
		</div>
<p><img src="http://www.thetutorialblog.com/wp-content/uploads/2010/02/cijqt.jpg" alt="CodeIngiter + jQuery=twitter" title="CodeIngiter + jQuery=twitter" width="471" height="211" class="alignleft size-full wp-image-257" /><br />
Don't forget to check out <a href="http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery/">part 1</a> if you have no read it.</p>
<p>In the second part of this 5 part tutorial series on how to build a Twitter-like website, we will be creating a signup form so that users can register to our website.</p>
<p>We will be adding records to the database that we created in part 1 and creating validation rules to make sure that the user didn't put any invalid data into the form.<br />
<span id="more-268"></span></p>
<h2>Change the base url</h2>
<p>Navigate to <em>ci_twitter->system->applications->config->config.php</em>.<br />
Change:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://example.com/&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To the path to where CodeIgniter is. On my machine it would be:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://tutorials:8888/ci_twitter/&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Create the controller</h2>
<p>We need to create a main controller for things such as the home page, sign up page, login page, etc. Go to <em>ci_twitter->system->application->controllers</em> then in the controllers folder create a file called main.php.</p>
<p>Inside our main controller we now need to define the class and the functions inside 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: #000000; font-weight: bold;">class</span> main <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main/index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> signup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main/signup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> signin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form'</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main/signin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If we were to go to <em>http://localhost/ci_twitter/index.php/main/</em> then we will see a blank page.</p>
<h2>Create the views</h2>
<p>Before we can see anything we need to create a folder for the functions in our main controller. Go to <em>ci_twitter->system->application->views</em>. Inside the views folder create another folder called main. In the main folder we will create files for each function that we have in the main controller.</p>
<p>Create these files in the main folder we created:</p>
<ul>
<li>index.php</li>
<li>signup.php</li>
<li>signup_success.php</li>
<li>signin.php</li>
</ul>
<p>Go to index.php and enter Hello World. Now if you go to <em>http://localhost/ci_twitter/index.php/main/</em> you will see Hello World.</p>
<p>The next thing to do is to add a form and text fields so that people can input data. For the sign up page the html is done in the signup.php view file. The validation and processing is done in the main controller inside the signup function.</p>
<p>Add the following code to the signup.php view:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;h2&gt;Sign up&lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> validation_errors<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> form_open<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main/signup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
Full name: &lt;input type=&quot;text&quot; name=&quot;name&quot; /&gt; &lt;br /&gt;
Username: &lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt; &lt;br /&gt;
Password: &lt;input type=&quot;password&quot; name=&quot;password&quot; /&gt; &lt;br /&gt;
Email: &lt;input type=&quot;text&quot; name=&quot;email&quot; /&gt; &lt;br /&gt;
&lt;input type=&quot;submit&quot; value=&quot;Create my account&quot; name=&quot;create&quot; /&gt;
&nbsp;
&lt;/form&gt;</pre></div></div>

<p>Then add this inside signup_success.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Your account was created, <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> anchor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main/signin'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'login here'</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>This is all that we need to do for the sign up view for now. Validation rules is what we will do next in the main controller for sign up.</p>
<h2>Validation</h2>
<p>When doing form validation all of the validation takes place inside of the controller. For now we will set basic validation rules for each field within the form.</p>
<p>In the main controller replace the code for the signup function with:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">function</span> signup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required|min_length[5]|max_length[50]|trim|xss_clean'</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;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required|min_length[5]|max_length[50]|trim|xss_clean'</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;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required|min_length[5]|max_length[50]|trim|xss_clean'</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;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required|min_length[5]|max_length[50]|valid_email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main/signup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main/signup_success'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you go to the sign up page now you should see that all the validation code works like it should. Now we will add a model so that we can add the user to the users table.</p>
<h2>Create user model</h2>
<p>Go to the model folder and create a file called User_model.php.</p>
<p>Insert this code into the model:</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> User_model <span style="color: #000000; font-weight: bold;">extends</span> Model <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> user_exists<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</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;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users'</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;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_username'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count_all_results</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> create_user<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fullname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_fullname'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$fullname</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'user_username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'user_email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'user_password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</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;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</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;">?&gt;</span></pre></div></div>

<p>Now we need to load the User_model in the controller.<br />
Insert this code in the signup function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'User_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We also need to add the user if the validation rules are passed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">User_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create_user</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</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;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</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;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</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;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main/signup_success'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Part 3</h2>
<p>In part 3 we will be creating a login page and functionality so that people can post messages.</p>
<h2>Download</h2>
<p><a href="http://bit.ly/c7ycMW">Download</a></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Build a Twitter-like site with CodeIgniter and jQuery</title>
		<link>http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery/</link>
		<comments>http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 15:39:07 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[build a social network]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[code igniter]]></category>
		<category><![CDATA[codeigniter series]]></category>
		<category><![CDATA[codeigniter tutorial]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[how to build a social network]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery series]]></category>
		<category><![CDATA[jquery tutorial]]></category>
		<category><![CDATA[php series]]></category>
		<category><![CDATA[series]]></category>
		<category><![CDATA[the tutorial blog]]></category>
		<category><![CDATA[twitter series]]></category>
		<category><![CDATA[twitter tutorial]]></category>
		<category><![CDATA[twitter-like tutorial]]></category>
		<category><![CDATA[wez pyke]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=256</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	This tutorial will be the first of a five part series where we will built a social network site similar to Twitter from scratch. We will be using the CodeIgniter framework for the core of the website and jQuery for the effects. In this first part we will be configuring CodeIgniter to display everything correctly [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fbuild-a-twitter-like-site-with-codeigniter-and-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fbuild-a-twitter-like-site-with-codeigniter-and-jquery%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Build a Twitter like site with CodeIgniter and jQuery" alt=" Build a Twitter like site with CodeIgniter and jQuery" /><br />
			</a>
		</div>
<p><img src="http://www.thetutorialblog.com/wp-content/uploads/2010/02/cijqt.jpg" alt="CodeIngiter + jQuery=twitter" title="CodeIngiter + jQuery=twitter" width="471" height="211" class="alignleft size-full wp-image-257" /></p>
<p>This tutorial will be the first of a five part series where we will built a social network site similar to <a href="http://www.twitter.com">Twitter</a> from scratch. We will be using the <a href="http://www.codeigniter.com">CodeIgniter</a> framework for the core of the website and <a href="http://www.jquery.com">jQuery</a> for the effects. In this first part we will be configuring CodeIgniter to display everything correctly and we will also set up a database and connect to it.</p>
<p><span id="more-256"></span></p>
<h2>Download and configure</h2>
<p>Download the <a href="http://www.codeigniter.com">CodeIgniter</a> framework from their website. We don't need to download anything for jQuery because we will be loading it directly from Google as it's quicker to load.</p>
<p>Once you have downloaded the latest version of CodeIgniter from their website, unzip it and copy the files to your public_html folder or equivalent. Rename the CodeIgniter folder to ci_twitter.</p>
<p>Now if you go to http://localhost/ci_twitter you should see something similar to the image below.<br />
<img src="http://www.thetutorialblog.com/wp-content/uploads/2010/02/ci.jpg" alt="ci Build a Twitter like site with CodeIgniter and jQuery" title="ci" width="650" height="458" class="alignleft size-full wp-image-261" /></p>
<h2>Database</h2>
<p>We now need configure a database to connect to CodeIgniter so that we can use it to insert and retrieve information. Go to phpMyAdmin or whatever you use for MySQL databases. Create a database called ci_twitter.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">DATABASE</span> <span style="color: #008000;">`ci<span style="color: #008080; font-weight: bold;">_</span>twitter`</span> <span style="color: #000033;">;</span></pre></div></div>

<p>For now we are only going to create a table for the users, in another part we will create other tables when we need them.</p>
<p><strong>users table</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"> <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`ci<span style="color: #008080; font-weight: bold;">_</span>twitter`</span>.<span style="color: #008000;">`users`</span> <span style="color: #FF00FF;">&#40;</span>
<span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #000033;">,</span>
<span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>fullname`</span> <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">50</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #000033;">,</span>
<span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>username`</span> <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">50</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #000033;">,</span>
<span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>email`</span> <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">50</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #000033;">,</span>
<span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>password`</span> <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">50</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #000033;">,</span>
<span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>protected<span style="color: #008080; font-weight: bold;">_</span>updates`</span> <span style="color: #999900; font-weight: bold;">TINYINT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">DEFAULT</span> <span style="color: #008000;">'0'</span><span style="color: #000033;">,</span>
<span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>location`</span> <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">50</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #000033;">,</span>
<span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>web`</span> <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">50</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #000033;">,</span>
<span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>bio`</span> <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">160</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">ENGINE</span> <span style="color: #CC0099;">=</span> MYISAM</pre></div></div>

<h2>Configure CodeIgniter</h2>
<p>Now that we have set up our database and have inserted a table we will configure CodeIgniter to connect to it.</p>
<p>Navigate to database.php by going to <em>ci_twitter -> system -> application -> config -> database.php</em>. From here enter the correct information for your database so that it connects.</p>
<p>We need to auto load the database library because we will be using it a lot.</p>
<p>Go to <em>autoload.php</em> in the same folder as <em>database.php</em>.</p>
<p>Change:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'libraries'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'libraries'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The database library will now load every time without us having to put $this->load->library('database'); in every controller.</p>
<h2>End of Part 1</h2>
<p>This is the end of the first part of approximately five parts.</p>
<h2>Part 2</h2>
<p>Part 2 will be following tomorrow. In part 2 we will be creating a sign up so that we can add users to the database.</p>
<h2>Download</h2>
<p>You can download part one from <a href="http://bit.ly/91HSQ0">here</a></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Twitter-like pagination using CakePHP and jQuery</title>
		<link>http://www.thetutorialblog.com/php/twitter-like-pagination-using-cakephp-and-jquery/</link>
		<comments>http://www.thetutorialblog.com/php/twitter-like-pagination-using-cakephp-and-jquery/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 00:26:26 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[wez pyke]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=179</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	I have already done this tutorial with CodeIgniter and jQuery it can be found here. I thought I would do this tutorial again but rewrite it for CakePHP because it is a popular PHP framework. Before we start doing any PHP code make sure to copy in the code below into your MySQL database. CREATE [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Ftwitter-like-pagination-using-cakephp-and-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Ftwitter-like-pagination-using-cakephp-and-jquery%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Twitter like pagination using CakePHP and jQuery" alt=" Twitter like pagination using CakePHP and jQuery" /><br />
			</a>
		</div>
<p><img src="http://www.thetutorialblog.com/wp-content/uploads/2009/12/twitter_pagination_icon.jpg" alt="twitter pagination icon Twitter like pagination using CakePHP and jQuery" title="twitter_pagination_icon" width="300" height="300" class="alignleft size-full wp-image-168" />I have already done this tutorial with CodeIgniter and jQuery it can be found <a href="http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/">here</a>. I thought I would do this tutorial again but rewrite it for CakePHP because it is a popular PHP framework.</p>
<p>Before we start doing any PHP code make sure to copy in the code below into your MySQL database.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span>  <span style="color: #ff0000;">`tutorials`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`twitter_messages`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`id`</span> INT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`username`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">30</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`message`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">140</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> INNODB</pre></div></div>

<h2>Create the controller</h2>
<p>Under the folder named controller create a file and call it twitter_controller.php.</p>
<p>We create a class inside it called TwitterController and it will extend AppController. We then set the name of the controller to twitter and tell CakePHP which table we are using in our database.<br />
<span id="more-179"></span></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> TwitterController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'twitter'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$uses</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'twitter_messages'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;</span>pre<span style="color: #339933;">&gt;</span>
&nbsp;
In this controller we will have two methods index and get_messages<span style="color: #339933;">.</span> Our index method will have no parameters and get_messages will have one parameter so that we know what the offset of the <span style="color: #990000;">current</span> number of messages loaded<span style="color: #339933;">.</span>
&nbsp;
Inside our index method we will retrieve the number of messages in the table and also the first <span style="color: #cc66cc;">10</span> records<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #339933;">&lt;</span>pre lang<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;php&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'num_messages'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_messages</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_messages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'messages'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_messages</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_messages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In our second method called get_messages we grab the 10 latest messages for when it is called via jQuery.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_messages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'latest_messages'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_messages</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_messages</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Model</h2>
<p>Under the models folder create a file and name it twitter_messages.php.</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> Twitter_messages <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'twitter_messages'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> get_messages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$messages</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'offset'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$offset</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'limit'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</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;">$messages</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> num_messages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'count'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>These two methods in the model are called from the controller.</p>
<h2>View</h2>
<p>Create a folder called twitter inside the views folder. Then create a file called index.ctp and get_messages.ctp.</p>
<h3>index.ctp</h3>
<p>Inside the index file copy this css and jQuery code.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;style&gt;
#main_content {
	border: #999 1px solid;
	-webkit-border-radius: 5px;
	-moz-border-radius: 5px;
	padding: 5px;
}
&nbsp;
#more_button {
	-webkit-border-radius: 5px;
	-moz-border-radius: 5px;
	color: #990000;
	text-align: center;
	padding: 5px;
	background-color: #fff;
	background-image: url(&quot;http://s.twimg.com/a/1261078355/images/more.gif&quot;);
	background-repeat: repeat-x;
	cursor: pointer;
	border: 1px solid #AAA;
}
&nbsp;
#more_button:hover {
	border:1px solid #bbb;
	text-decoration:none;
	background-position:left -78px;
}
&lt;/style&gt;
&lt;script src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
google.load(&quot;jquery&quot;, &quot;1.3.2&quot;);
&lt;/script&gt;
&nbsp;
&lt;script type=&quot;text/javascript&quot;&gt;
		$(document).ready(function(){
		var num_messages = &lt;?=$num_messages?&gt;;
		var loaded_messages = 0;
			$(&quot;#more_button&quot;).click(function(){
				loaded_messages += 10;
				$.get(&quot;twitter/get_messages/&quot; + loaded_messages, function(data){
					$(&quot;#main_content&quot;).append(data);
&nbsp;
				});
&nbsp;
				if(loaded_messages &gt;= num_messages - 10)
				{
					$(&quot;#more_button&quot;).hide();
					//alert('hide');
				}
			})
		})
	&lt;/script&gt;</pre></div></div>

<p>Below this copy in the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;main_content&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$messages</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'twitter_messages'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' - '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'twitter_messages'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
&nbsp;
&lt;div id=&quot;more_button&quot;&gt;
	more
&lt;/div&gt;</pre></div></div>

<p>Here we are displaying the first 10 records in the database then when the more button is clicked an ajax request will retrieve 10 more.</p>
<h3>get_messages.ctp</h3>
<p>This file is the file that is called upon the ajax request. This will display the 10 latest retrieve records.</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;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$latest_messages</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'twitter_messages'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' - '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'twitter_messages'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Final words</h2>
<p>I hope this tutorial has been useful to you, please Retweet it if it was useful for you. You can also follow me <a href="http://twitter.com/wezpyke">@wezpyke</a></p>
<h2>Download</h2>
<p><a href="http://bit.ly/91Rptr">Download the resources for this tutorial</a></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/twitter-like-pagination-using-cakephp-and-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP gallery with no page reloads using jQuery</title>
		<link>http://www.thetutorialblog.com/php/php-gallery-with-no-page-reloads-using-jquery/</link>
		<comments>http://www.thetutorialblog.com/php/php-gallery-with-no-page-reloads-using-jquery/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 18:02:09 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[image gallery]]></category>
		<category><![CDATA[image gallery using ajax]]></category>
		<category><![CDATA[imgbrowz0r]]></category>
		<category><![CDATA[php image gallery]]></category>
		<category><![CDATA[prettyPhoto]]></category>
		<category><![CDATA[thetutorialblog]]></category>
		<category><![CDATA[wez pyke]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=173</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	For this tutorial we will be using the ImgBrowz0r class for the backend of the gallery, we will then write a jQuery script so that we can browse through the gallery created by ImgBrowz0r without no page reloads and a nice effect between page requests so the user knows the page has changed. We will [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-gallery-with-no-page-reloads-using-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-gallery-with-no-page-reloads-using-jquery%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="PHP gallery with no page reloads using jQuery" alt=" PHP gallery with no page reloads using jQuery" /><br />
			</a>
		</div>
<p><img src="http://www.thetutorialblog.com/wp-content/uploads/2009/12/jquery_gallery.jpg" alt="jquery gallery PHP gallery with no page reloads using jQuery" title="jquery_gallery" width="300" height="300" class="alignleft size-full wp-image-174" />For this tutorial we will be using the <a href="http://61924.nl/projects/imgbrowz0r.html">ImgBrowz0r</a> class for the backend of the gallery, we will then write a jQuery script so that we can browse through the gallery created by ImgBrowz0r without no page reloads and a nice effect between page requests so the user knows the page has changed. We will also be using the <a href="http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/">prettyPhoto plugin</a> for jQuery to open up the actual images.</p>
<h2>Getting ImgBrowz0r and prettyPhoto to work</h2>
<p>The first thing I done was create a folder called jquery_gallery inside here is where all the files and folders are gonna be stored. I then created 4 folders inside jquery_gallery, the folders are called css, images, inc and js.</p>
<p>When you have downloaded the ImgBrowz0r class, copy the file into the inc folder.<br />
<span id="more-173"></span><br />
Now inside the images folder create 2 folders cache and gallery. After you have unzipped prettyPhoto goto the images folder and inside the images folder copy the folder named prettyPhoto to our image folder. There should now be 3 folders inside our images folder cache, gallery and prettyPhoto.</p>
<p>Inside our css folder that we have created we will copy the css file from the prettyPhoto css folder named prettyPhoto.css.</p>
<p>The last thing to do for prettyPhoto is to copy the javascript file from the prettyPhoto js folder to our js folder.</p>
<p>So now we should have a file structure like so:<br />
|css<br />
|--prettyPhoto.css</p>
<p>|images<br />
|--cache<br />
|--gallery<br />
|--prettyPhoto</p>
<p>|inc<br />
|--imgbrowz0r.php</p>
<p>|js<br />
|--jquery.prettyPhoto.js</p>
<p>We need to also create a css file for our imgBrowz0r class, create a css file inside our css folder and name it gallery.css. Copy the code into this file that is below:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">strong <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* This is some example CSS. You can change this to your own liking. */</span>
	<span style="color: #6666ff;">.img-description</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.imgbrowz0r-navigation</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span> <span style="color: #933;">970px</span><span style="color: #00AA00;">;</span>text-align<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.imgbrowz0r-navigation</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">0.5em</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.imgbrowz0r-navigation</span> <span style="color: #6666ff;">.img-statistics</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.img-description</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span> <span style="color: #993333;">auto</span> <span style="color: #cc66cc;">0</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-row</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1em</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> a<span style="color: #3333ff;">:link</span><span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> a<span style="color: #3333ff;">:visited </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> Georgia<span style="color: #00AA00;">,</span> <span style="color: #ff0000;">&quot;Times New Roman&quot;</span><span style="color: #00AA00;">,</span> Times<span style="color: #00AA00;">,</span> <span style="color: #993333;">serif</span><span style="color: #00AA00;">;</span>text-decoration<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-thumbnail</span> a<span style="color: #3333ff;">:link </span>img<span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-thumbnail</span> a<span style="color: #3333ff;">:visited </span>img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-thumbnail</span> a<span style="color: #3333ff;">:hover </span>img<span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-thumbnail</span> a<span style="color: #3333ff;">:active </span>img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> a<span style="color: #3333ff;">:link</span><span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> a<span style="color: #3333ff;">:visited </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>border<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>font-<span style="color: #000000; font-weight: bold;">size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ccc</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> a<span style="color: #3333ff;">:active </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> span.img-dir-name<span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> span<span style="color: #6666ff;">.img-thumb-date</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> span<span style="color: #6666ff;">.img-dir-name</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>font-<span style="color: #000000; font-weight: bold;">size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.2em</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-thumbnail</span> a<span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>margin<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#imgbrowz0r</span> .img-thumbnail<span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">25</span>%</span><span style="color: #00AA00;">;</span>text-align<span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-column-1</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> a<span style="color: #3333ff;">:link</span><span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#imgbrowz0r</span> <span style="color: #6666ff;">.img-directory</span> a<span style="color: #3333ff;">:visited </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>line-<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
					       <span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>background-<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span> <span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* http://sonspring.com/journal/clearing-floats */</span>
	html body div.<span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">,</span>
	html body span<span style="color: #6666ff;">.clear</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>border<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>clear<span style="color: #00AA00;">:</span> <span style="color: #993333;">both</span><span style="color: #00AA00;">;</span>display<span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>float<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>font-<span style="color: #000000; font-weight: bold;">size</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>list-style<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
			       <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>overflow<span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>visibility<span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>height<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Create a file called index.php in the root of our folder and copy in the basic html.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
	&lt;title&gt;TheTutorialBlog.com | Photo Gallery&lt;/title&gt;
	&lt;script src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	google.load(&quot;jquery&quot;, &quot;1.3.2&quot;);
	&lt;/script&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;css/prettyPhoto.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;no title&quot; charset=&quot;utf-8&quot;&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;css/gallery.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;no title&quot; charset=&quot;utf-8&quot;&gt;
	&lt;script src=&quot;js/jquery.prettyPhoto.js&quot;&gt;&lt;/script&gt;
&nbsp;
	&lt;script&gt;
		$(document).ready(function(){
		// prettyPhoto
			$(&quot;a[rel^='prettyPhoto']&quot;).prettyPhoto({
				showTitle: false
			});
	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;content_main&quot;&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Inside the div called content_main is where our the ImgBrowz0r class code will go.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'inc/imgbrowz0r.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// These are all settings (set to default). The settings are not validated since you have to configure everything.</span>
<span style="color: #666666; font-style: italic;">// There is a chance that ImgBrowz0r stops working if you enter the wrong values.</span>
<span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #666666; font-style: italic;">// Directory settings. These are required. Without trailing slash. (required)</span>
	<span style="color: #0000ff;">'images_dir'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'images/gallery'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'cache_dir'</span>                <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'images/cache'</span><span style="color: #339933;">,</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Url settings. These are required. Without trailing slash. (required)</span>
	<span style="color: #666666; font-style: italic;">// %PATH% is replaced with the directory location and page number</span>
	<span style="color: #0000ff;">'main_url'</span>                 <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://localhost:8888/tutorials/jquery_gallery/index.php?q=%PATH%'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'images_url'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http:///localhost:8888/tutorials/jquery_gallery/images/gallery'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'cache_url'</span>                <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http:///localhost:8888/tutorials/jquery_gallery/images/cache'</span><span style="color: #339933;">,</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Sorting settings (optional)</span>
	<span style="color: #0000ff;">'sort_by'</span>                  <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// 1 = filename, 2 = extension (png, gif, etc.), 3 = inode change time of file</span>
	<span style="color: #0000ff;">'sort_order'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// true = ascending, false = descending</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Thumbnail settings (optional)</span>
	<span style="color: #0000ff;">'thumbs_per_page'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Amount of thumbnails per page</span>
	<span style="color: #0000ff;">'max_thumb_row'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Amount of thumbnails on a row</span>
	<span style="color: #0000ff;">'max_thumb_width'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Maximum width of thumbnail</span>
	<span style="color: #0000ff;">'max_thumb_height'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Maximum height of thumbnail</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Time settings (optional)</span>
	<span style="color: #0000ff;">'time_format'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'F jS, Y'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Date formatting. Look at the PHP date() for help: http://nl3.php.net/manual/en/function.date.php</span>
	<span style="color: #0000ff;">'time_zone'</span>                <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Timezone. Example: 1</span>
	<span style="color: #0000ff;">'enable_dst'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Daylight saving time (DST). Set this to true to enable it.</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Misc settings (optional)</span>
	<span style="color: #0000ff;">'ignore_port'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Ignore port in url. Set this to true to ignore the port.</span>
	<span style="color: #0000ff;">'dir_thumbs'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Show a thumbnail in a category box. Default is false.</span>
	<span style="color: #0000ff;">'random_thumbs'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Use random thumbnails for categories. Default is false.</span>
	<span style="color: #0000ff;">'read_thumb_limit'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #666666; font-style: italic;">// See README for information about this setting.</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Start the class</span>
<span style="color: #000088;">$gallery</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> imgbrowz0r<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Prepare everything. This function must be called before you call other functions.</span>
<span style="color: #000088;">$gallery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Generate navigation and statistics</span>
<span style="color: #000088;">$gallery_breadcrumbs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gallery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">breadcrumbs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$gallery_pagination</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gallery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pagination</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Display navigation</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;imgbrowz0r-navigation&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gallery_breadcrumbs</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gallery_pagination</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Display images and directories</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$gallery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">browse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Display navigation</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;imgbrowz0r-navigation&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gallery_pagination</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gallery_breadcrumbs</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Fill in the information for the main_url, images_url and cache_url or it will not work.</p>
<p>In the imgBrowz0r.php file located in inc find line number 205 and add a rel called prettyPhoto:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cur_directory</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot; title=&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot; rel=&quot;prettyPhoto&quot;&gt;&lt;img src=&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cache_url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span></pre></div></div>

<p>If we do not do this then the jQuery prettyPhoto plugin will not work.</p>
<h2>Navigating through the gallery without page reloads</h2>
<p>To do this we need to write our own jQuery code so that when a hyperlink inside the gallery div then we will do an ajax call that will then replace the content in the content_main div.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.img-directory a'</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: #660066;">get</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;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#content_main&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</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: #3366CC;">&quot;#content_main&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</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: #3366CC;">&quot;#content_main&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>So when a hyperlink inside the a div with the class called img-directory is clicked we will get the href from the hyperlink and retrieve that page using $.get(). We will then slide up the element until the content has loaded and then the elemnt will slide back down and contain the content we requested. We also return false so that the page does not reload.</p>
<p>We do the same for the breadcrumbs so we can navigate between them without the page refreshing also:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.img-breadcrumbs'</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: #660066;">get</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;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#content_main&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</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: #3366CC;">&quot;#content_main&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</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: #3366CC;">&quot;#content_main&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The entire index.php page should look like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
	&lt;title&gt;TheTutorialBlog.com | Photo Gallery&lt;/title&gt;
	&lt;script src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	google.load(&quot;jquery&quot;, &quot;1.3.2&quot;);
	&lt;/script&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;css/prettyPhoto.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;no title&quot; charset=&quot;utf-8&quot;&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;css/gallery.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;no title&quot; charset=&quot;utf-8&quot;&gt;
	&lt;script src=&quot;js/jquery.prettyPhoto.js&quot;&gt;&lt;/script&gt;
&nbsp;
	&lt;script&gt;
		$(document).ready(function(){
		// prettyPhoto
			$(&quot;a[rel^='prettyPhoto']&quot;).prettyPhoto({
				showTitle: false
			});
&nbsp;
			$('.img-directory a').click(function(){
				$.get($(this).attr(&quot;href&quot;), function(data){
					$(&quot;#content_main&quot;).slideUp(&quot;slow&quot;, function(){
					$(&quot;#content_main&quot;).html(data)}), $(&quot;#content_main&quot;).slideDown()
				});
				return false;
			})
&nbsp;
			$('.img-breadcrumbs').click(function(){
				$.get($(this).attr(&quot;href&quot;), function(data){
					$(&quot;#content_main&quot;).slideUp(&quot;slow&quot;, function(){
					$(&quot;#content_main&quot;).html(data)}), $(&quot;#content_main&quot;).slideDown()
				});
				return false;
			});
		});
	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
<span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'inc/imgbrowz0r.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// These are all settings (set to default). The settings are not validated since you have to configure everything.</span>
<span style="color: #666666; font-style: italic;">// There is a chance that ImgBrowz0r stops working if you enter the wrong values.</span>
<span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #666666; font-style: italic;">// Directory settings. These are required. Without trailing slash. (required)</span>
	<span style="color: #0000ff;">'images_dir'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'images/gallery'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'cache_dir'</span>                <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'images/cache'</span><span style="color: #339933;">,</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Url settings. These are required. Without trailing slash. (required)</span>
	<span style="color: #666666; font-style: italic;">// %PATH% is replaced with the directory location and page number</span>
	<span style="color: #0000ff;">'main_url'</span>                 <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://localhost:8888/tutorials/jquery_gallery/index.php?q=%PATH%'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'images_url'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http:///localhost:8888/tutorials/jquery_gallery/images/gallery'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'cache_url'</span>                <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http:///localhost:8888/tutorials/jquery_gallery/images/cache'</span><span style="color: #339933;">,</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Sorting settings (optional)</span>
	<span style="color: #0000ff;">'sort_by'</span>                  <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// 1 = filename, 2 = extension (png, gif, etc.), 3 = inode change time of file</span>
	<span style="color: #0000ff;">'sort_order'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// true = ascending, false = descending</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Thumbnail settings (optional)</span>
	<span style="color: #0000ff;">'thumbs_per_page'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Amount of thumbnails per page</span>
	<span style="color: #0000ff;">'max_thumb_row'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Amount of thumbnails on a row</span>
	<span style="color: #0000ff;">'max_thumb_width'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Maximum width of thumbnail</span>
	<span style="color: #0000ff;">'max_thumb_height'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Maximum height of thumbnail</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Time settings (optional)</span>
	<span style="color: #0000ff;">'time_format'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'F jS, Y'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Date formatting. Look at the PHP date() for help: http://nl3.php.net/manual/en/function.date.php</span>
	<span style="color: #0000ff;">'time_zone'</span>                <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Timezone. Example: 1</span>
	<span style="color: #0000ff;">'enable_dst'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Daylight saving time (DST). Set this to true to enable it.</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Misc settings (optional)</span>
	<span style="color: #0000ff;">'ignore_port'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Ignore port in url. Set this to true to ignore the port.</span>
	<span style="color: #0000ff;">'dir_thumbs'</span>               <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Show a thumbnail in a category box. Default is false.</span>
	<span style="color: #0000ff;">'random_thumbs'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Use random thumbnails for categories. Default is false.</span>
	<span style="color: #0000ff;">'read_thumb_limit'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #666666; font-style: italic;">// See README for information about this setting.</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Start the class</span>
<span style="color: #000088;">$gallery</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> imgbrowz0r<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Prepare everything. This function must be called before you call other functions.</span>
<span style="color: #000088;">$gallery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Generate navigation and statistics</span>
<span style="color: #000088;">$gallery_breadcrumbs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gallery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">breadcrumbs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$gallery_pagination</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gallery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pagination</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div id=&quot;content_main&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Display navigation</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;imgbrowz0r-navigation&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gallery_breadcrumbs</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gallery_pagination</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Display images and directories</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$gallery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">browse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Display navigation</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;imgbrowz0r-navigation&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gallery_pagination</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gallery_breadcrumbs</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;&lt;!--content_main--&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<h2>Download</h2>
<p>You can download the files used in this tutorial <a href="http://www.thetutorialblog.com/files/tutorials/jquery_gallery.zip">here</a></p>
<h2>Final words</h2>
<p>I hope this tutorial has been useful for you and that you can take something you have learnt from it and use it in future projects.</p>
<p>Please feel free to leave a comment.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/php-gallery-with-no-page-reloads-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter-like pagination using CodeIgniter and jQuery</title>
		<link>http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/</link>
		<comments>http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 16:30:57 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[twitter pagination]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=167</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	If you use Twitter you'll notice that there is a more button at the bottom at the bottom of your timeline, when you click this more tweets appear. This is Twitters way of paginating a page. In this tutorial I'll show you how to create a pagination system using CodeIgniter and jQuery that is almost [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Ftwitter-like-pagination-using-codeigniter-and-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Ftwitter-like-pagination-using-codeigniter-and-jquery%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Twitter like pagination using CodeIgniter and jQuery" alt=" Twitter like pagination using CodeIgniter and jQuery" /><br />
			</a>
		</div>
<p><img src="http://www.thetutorialblog.com/wp-content/uploads/2009/12/twitter_pagination_icon.jpg" alt="twitter pagination icon Twitter like pagination using CodeIgniter and jQuery" title="twitter_pagination_icon" width="300" height="300" class="alignleft size-full wp-image-168" />If you use Twitter you'll notice that there is a more button at the bottom at the bottom of your timeline, when you click this more tweets appear. This is Twitters way of paginating a page. In this tutorial I'll show you how to create a pagination system using CodeIgniter and jQuery that is almost identical to Twitters.</p>
<p>First of all copy this SQL into your database to create a table that we will be using to grab rows from.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span>  <span style="color: #ff0000;">`tutorials`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`twitter_messages`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`id`</span> INT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`username`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">30</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`message`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">140</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> INNODB</pre></div></div>

<p><span id="more-167"></span></p>
<h2>Create the controller</h2>
<p>The class we create is going to be called twitterpagination:</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> twitterpagination <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>inside the controller class create a function called index()</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitterpagination_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'num_messages'</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;">twitterpagination_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_messages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'latest_messages'</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;">twitterpagination_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_messages</span><span style="color: #009900;">&#40;</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitterpagination/index'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We load the url helper because we will be using base_url() in our view to link to our stylesheet. The model we will be creating is twitterpagination_model so we call this also. $data['num_messages'] returns the number of messages in the database and $data['lastest_messages'] loads the 10 newest rows from the database. Lastly we include a view that we will be creating and pass in $data.</p>
<p>Inside the controller I have created two more functions insert_rows() and get_messages(). The function insert_rows() will insert 50 examples rows for us to retrieve from the table.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> insert_rows<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">database</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'message '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$i</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;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter_messages'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The last function we have in our controller is get_messages()</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_messages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitterpagination_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'latest_messages'</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;">twitterpagination_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_messages</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitterpagination/get_messages'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This function will be called from the view using an ajax call. We have one parameter called $offset, we use this so we know where to pull the next set of rows from in the table. We simply include the twitterpagination_model, call the get_messages() function from the model and pass in the data to the view.</p>
<p>Here is all of the controller code:</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> twitterpagination <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitterpagination_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'num_messages'</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;">twitterpagination_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_messages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'latest_messages'</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;">twitterpagination_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_messages</span><span style="color: #009900;">&#40;</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitterpagination/index'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> insert_rows<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">database</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
			<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'message '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$i</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;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter_messages'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> get_messages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitterpagination_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'latest_messages'</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;">twitterpagination_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_messages</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitterpagination/get_messages'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Save this file as twitterpagination.php inside the controllers folder.</p>
<h2>The Model</h2>
<p>For the model we create a file called twitterpagination_model.php inside the models folder. Then we create a class called twitterpagination_model which extends Model.</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> twitterpagination_model <span style="color: #000000; font-weight: bold;">extends</span> Model <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next we create the function that will pull the messages from the table.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_messages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">order_by</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'desc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter_messages'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We order the ID descending so that the newest rows are called first. Then we create a variable called $query and retrieve the 10 latest messages from twitter_messages.</p>
<p>Another function that we create in the model is num_messages(). This function returns the number of messages and will be call in the view. This is so we know how many messages are in the table and when to hide the "more" button in the view so the user cannot see it anymore.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> num_messages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count_all_results</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter_messages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That is all we need to do for the controller.</p>
<h2>The View</h2>
<p>First of all create a folder called twitterpagination inside the views folder, then create two files called index.php and get_messages.php.</p>
<h2>The code for index.php</h2>
<p>The most important thing about this file is not to forget to include the jQuery library or the code will not work at all.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;script src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
google.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;jquery&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;1.3.2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Just below the inclusion of the jQuery library we will write our javascript.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> num_messages <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;?=</span>$num_messages<span style="color: #339933;">?&gt;;</span>
	<span style="color: #003366; font-weight: bold;">var</span> loaded_messages <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#more_button&quot;</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>
			loaded_messages <span style="color: #339933;">+=</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span>
			$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;twitterpagination/get_messages/&quot;</span> <span style="color: #339933;">+</span> loaded_messages<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#main_content&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>loaded_messages <span style="color: #339933;">&gt;=</span> num_messages <span style="color: #339933;">-</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#more_button&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #006600; font-style: italic;">//alert('hide');</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>After we have checked the DOM is ready we create two variables called num_messages and loaded_messages. The variable num_messages is the total number of messages in the table and loaded_messages will increase by 10 every time 10 more rows are retrieved.</p>
<p>We then have a click event for our more button that will send a request to the get_messages view that we will create.</p>
<p>Then we check if the number of loaded messages is the same as the total number off messages so that we know to hide the more button as there are no more rows to retrieve.</p>
<p>The next thing to do is to include the stylesheet.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?=base_url();?&gt;stylesheet/main.css&quot; type=&quot;text/css&quot; /&gt;</pre></div></div>

<p>Inside the body we include this html:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;main_content&quot;&gt;
&lt;?php
foreach($latest_messages as $message)
{
	echo $message-&gt;username . ' - ' . $message-&gt;message . '&lt;br /&gt;';
}
?&gt;
&lt;/div&gt;
&lt;div id=&quot;more_button&quot;&gt;
more
&lt;/div&gt;</pre></div></div>

<p>The div with the id of main_content is where the messages will be loaded and the div with id of more_button is our button that will be clicked to retrieve more messages.</p>
<p>Here is the full html/javascript of the index.php page.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
	&lt;title&gt;Twitter Pagination&lt;/title&gt;
	&lt;script src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	google.load(&quot;jquery&quot;, &quot;1.3.2&quot;);
	&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		$(document).ready(function(){
		var num_messages = &lt;?=$num_messages?&gt;;
		var loaded_messages = 0;
			$(&quot;#more_button&quot;).click(function(){
				loaded_messages += 10;
				$.get(&quot;twitterpagination/get_messages/&quot; + loaded_messages, function(data){
					$(&quot;#main_content&quot;).append(data);
&nbsp;
				});
&nbsp;
				if(loaded_messages &gt;= num_messages - 10)
				{
					$(&quot;#more_button&quot;).hide();
					//alert('hide');
				}
			})
		})
	&lt;/script&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?=base_url();?&gt;stylesheet/main.css&quot; type=&quot;text/css&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div id=&quot;main_content&quot;&gt;
	&lt;?php
	foreach($latest_messages as $message)
	{
		echo $message-&gt;username . ' - ' . $message-&gt;message . '&lt;br /&gt;';
	}
	?&gt;
	&lt;/div&gt;
	&lt;div id=&quot;more_button&quot;&gt;
	more
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>The second view that we create is get_messages.php. This is the page that is called when the more button is clicked.</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;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$latest_messages</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' - '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Stylesheet</h2>
<p>The very last thing we need to do is create a stylesheet for our page to make it look a little nicer.</p>
<p>Create a folder named stylesheet in the root of the CodeIgniter folder and create a file in it called main.css. The path should be {CI_root}/stylesheet/main.php.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#main_content</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#999</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#more_button</span> <span style="color: #00AA00;">&#123;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#990000</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;http://s.twimg.com/a/1261078355/images/more.gif&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">repeat-x</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#AAA</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#more_button</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#bbb</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span> <span style="color: #933;">-78px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2>Conclusion</h2>
<p>Don't forget to configure your database.php file in the config folder and also inside autoload.php make sure you auto load the database library.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'libraries'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I hope this tutorial has been of use to you, please feel free to post your thoughts and modifications.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding security to CodeIgniter forms with a custom library class</title>
		<link>http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/</link>
		<comments>http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 14:03:48 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=159</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	The class that we are going to create within CI will simply add a math question that the user will have to enter correctly to continue. This is useful to stop bots from mass submitting information to your forms. The class we are going to write is only very short and simple, but it will [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fadding-security-to-codeigniter-forms-with-a-custom-library-class%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fadding-security-to-codeigniter-forms-with-a-custom-library-class%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Adding security to CodeIgniter forms with a custom library class" alt=" Adding security to CodeIgniter forms with a custom library class" /><br />
			</a>
		</div>
<p>The class that we are going to create within CI will simply add a math question that the user will have to enter correctly to continue. This is useful to stop bots from mass submitting information to your forms.</p>
<p>The class we are going to write is only very short and simple, but it will give you an idea of how to create classes for your own projects.</p>
<h2>Creating the new class</h2>
<p>First of all we need to create the file for the class, navigate to libraries then create a file called math_question.php.</p>
<p>All we are going to do within this class is generate two random numbers that will be added together.<br />
<span id="more-159"></span></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> math_question <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> questionOne<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;">// generate a random number between 0 - 10</span>
		<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$num</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> questionTwo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$num</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is all we will be doing for the code within the class.</p>
<h2>Using the class within a form</h2>
<p>To use this class in our controller we load it like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We will also be using form validation and sessions to check if the user has entered the correct answer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We need to set questionOne and questionTwo in variables so we can assign them to a temporary flash session and because they will be passed into the view.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$questionOne</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">math_question</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionOne</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$questionTwo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">math_question</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionTwo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionOne'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$questionOne</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;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionTwo'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$questionTwo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;What is <span style="color: #006699; font-weight: bold;">{$questionOne}</span> + <span style="color: #006699; font-weight: bold;">{$questionTwo}</span>?&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To check that the answer that is wrote in is correct we use the callback method in our form validation to call a function that we create that will check the users input against the flash data.</p>
<p>This is how we set our form validation:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Math Question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'callback_math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then we check if the validation has been executed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact/form'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we need to create our function that is called upon validation of the form:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> math_question<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$user_answer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$questionOne</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionOne'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$questionTwo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionTwo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$correct_answer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$questionOne</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$questionTwo</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_answer</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$correct_answer</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Your answer to the math question was incorrect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #b1b100;">else</span> <span style="color: #009900;">&#123;</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: #009900;">&#125;</span></pre></div></div>

<p>This will check if what the user has input is correct against a temporary flash session.</p>
<p>Here is all of the controller code in full:</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> Contact <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$questionOne</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">math_question</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionOne</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$questionTwo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">math_question</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionTwo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionOne'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$questionOne</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;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionTwo'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$questionTwo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;What is <span style="color: #006699; font-weight: bold;">{$questionOne}</span> + <span style="color: #006699; font-weight: bold;">{$questionTwo}</span>?&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Math Question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'callback_math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact/form'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> math_question<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$user_answer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$questionOne</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionOne'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$questionTwo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionTwo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$correct_answer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$questionOne</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$questionTwo</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_answer</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$correct_answer</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Your answer to the math question was incorrect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #b1b100;">else</span> <span style="color: #009900;">&#123;</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: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Create the view</h2>
<p>The last thing we need to do is create the view. Goto views and create a folder called contact, within that folder create a file called form.php.</p>
<p>Here is the code for form.php</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;">echo</span> validation_errors<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> form_open<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
Name: &lt;input type=&quot;text&quot; name=&quot;name&quot; /&gt; &lt;br /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$math_question</span><span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;br /&gt;
Answer: &lt;input type=&quot;text&quot; name=&quot;math_question&quot; /&gt; &lt;br /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Send!&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> form_close<span style="color: #009900;">&#40;</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>On the first line we output the validation errors if there is any, on the second line we use the form helper to open the form tags and likewise for the bottom line where we close the form. $math_question is the variable that is passed in from the controller.</p>
<h2>Post your thoughts</h2>
<p>Let us know what you think of the tutorial and share your thoughts and contributions below in the comments.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Resolving conflicting problems between jQuery and MooTools or any other Javascript library</title>
		<link>http://www.thetutorialblog.com/text-tutorials/quick-tip-resolving-conflicting-problems-between-jquery-and-mootools-or-any-other-javascript-library/</link>
		<comments>http://www.thetutorialblog.com/text-tutorials/quick-tip-resolving-conflicting-problems-between-jquery-and-mootools-or-any-other-javascript-library/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 23:51:10 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[conflict]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[quicktip]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=155</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	Recently I wrote quite a huge chunk of jQuery for a website and it worked fine. A few days later I checked back to make sure that everything was working correctly after modifying a few things, but to my surprise none of the jQuery code worked. The problem was that I had added some Mootools [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Ftext-tutorials%2Fquick-tip-resolving-conflicting-problems-between-jquery-and-mootools-or-any-other-javascript-library%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Ftext-tutorials%2Fquick-tip-resolving-conflicting-problems-between-jquery-and-mootools-or-any-other-javascript-library%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Quick Tip: Resolving conflicting problems between jQuery and MooTools or any other Javascript library" alt=" Quick Tip: Resolving conflicting problems between jQuery and MooTools or any other Javascript library" /><br />
			</a>
		</div>
<p>Recently I wrote quite a huge chunk of jQuery for a website and it worked fine. A few days later I checked back to make sure that everything was working correctly after modifying a few things, but to my surprise none of the jQuery code worked. The problem was that I had added some Mootools code, the Mootools code worked fine but the jQuery code did not. I done some searching and found that the two libraries were conflicting and all it takes is 2 extra lines of code to prevent this from happening.</p>
<p><span id="more-155"></span></p>
<p>If you was to include jQuery and Mootools together this code below would not work:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello World!&quot;</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></pre></div></div>

<p>But if we simply add <em>jQuery(function($){</em> and <em>});</em> then this code would work the way that we have intended.</p>
<p>The code would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<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>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello World!&quot;</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;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>More information</h2>
<p>I hope you found this quick tip useful, you can find out more about jQuery conflicts <a href="http://docs.jquery.com/Using_jQuery_with_Other_Libraries">here</a>.</p>
<p>Feel free to leave a comment with your thoughts.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/text-tutorials/quick-tip-resolving-conflicting-problems-between-jquery-and-mootools-or-any-other-javascript-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploading files to Rackspace Cloud (Mosso) using PHP API</title>
		<link>http://www.thetutorialblog.com/php/uploading-files-to-rackspace-cloud-mosso-using-php-api/</link>
		<comments>http://www.thetutorialblog.com/php/uploading-files-to-rackspace-cloud-mosso-using-php-api/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 00:39:45 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[mosso]]></category>
		<category><![CDATA[rackspace]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=142</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	Rackspace Cloud is a great VPS service, but when I recently done a project it needed the functionality of uploading directly from a website to the cloud. I did not find many tutorials on how to do this, so I thought I'd write a tutorial on it myself. Step 1: Download the required files The [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fuploading-files-to-rackspace-cloud-mosso-using-php-api%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fuploading-files-to-rackspace-cloud-mosso-using-php-api%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Uploading files to Rackspace Cloud (Mosso) using PHP API" alt=" Uploading files to Rackspace Cloud (Mosso) using PHP API" /><br />
			</a>
		</div>
<p><a title="Rackspace Cloud" href="http://www.rackspacecloud.com/">Rackspace Cloud</a> is a great <a title="VPS ( Virtual Private Server )" href="http://en.wikipedia.org/wiki/Virtual_private_server">VPS</a> service, but when I recently done a project it needed the functionality of uploading directly from a website to the cloud. I did not find many tutorials on how to do this, so I thought I'd write a tutorial on it myself.</p>
<h2>Step 1: Download the required files</h2>
<p>The files you will need for this are located at the Rackspace Cloud website <a title="API Files" href="http://www.rackspacecloud.com/cloud_hosting_products/files/#filesAPI">here</a>. You can download the API for <a href="http://www.php.net">PHP</a>, <a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29">Java</a>, <a href="http://www.python.org/">Python</a>, <a href="http://en.wikipedia.org/wiki/.NET_Framework">.NET</a> and <a href="http://www.ruby-lang.org/en/">Ruby</a>. But for this tutorial we will be using PHP.<br />
<span id="more-142"></span></p>
<h2>Step 2: Setup</h2>
<p>When the download of the PHP API has complete decompress the file and rename it to cloudfiles. Now place the folder named <em>cloudfiles </em>in the directory where the PHP files will be stored that will upload to the Rackspace Cloud.</p>
<h2>Step 3: Create an upload form</h2>
<p>For this tutorial we will only be creating a basic upload form, but I have planned for a more advanced uploader with a progress bar and multiple file uploads for a future tutorial, so be sure to check back for that.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;upload.php&quot; enctype=&quot;multipart/form-data&quot; method=&quot;POST&quot;&gt;
File: &lt;input name=&quot;upload&quot; type=&quot;file&quot; /&gt; 
&nbsp;
&lt;input name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Upload To Rackspace!&quot; /&gt;
&lt;/form&gt;</pre></div></div>

<p>Name this file <em>upload.html</em></p>
<h2>Step 4: Uploading to Rackspace Cloud</h2>
<p>So what we need to do to upload to the Rackspace cloud is to include the PHP API, connect to Rackspace, get the container we want to use, create an object and then upload the file to that object.</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: #666666; font-style: italic;">// include the API</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cloudfiles/cloudfiles.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cloud info</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// username</span>
<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// api key</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Connect to Rackspace</span>
<span style="color: #000088;">$auth</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CF_Authentication<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CF_Connection<span style="color: #009900;">&#40;</span><span style="color: #000088;">$auth</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get the container we want to use</span>
<span style="color: #000088;">$container</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_container</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ContainerName'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// store file information</span>
<span style="color: #000088;">$localfile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'upload'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'upload'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// upload file to Rackspace</span>
<span style="color: #000088;">$object</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$container</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load_from_filename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$localfile</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>Name this file <em>upload.php</em>.</p>
<h2>Download</h2>
<p>You can download the source files from <a title="Rackspace Cloud Upload source files" href="http://www.thetutorialblog.com/files/tutorials/rackspace_cloud_upload.zip">here</a></p>
<h2>Post a comment</h2>
<p>Please post a comment and let us know if you have anything that you'd like to add to the tutorial or if you are having any problems.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/uploading-files-to-rackspace-cloud-mosso-using-php-api/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Send form data to PHP without the whole page reloading using jQuery</title>
		<link>http://www.thetutorialblog.com/php/send-form-data-to-php-without-the-whole-page-reloading-using-jquery/</link>
		<comments>http://www.thetutorialblog.com/php/send-form-data-to-php-without-the-whole-page-reloading-using-jquery/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 00:43:14 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[nettuts]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[screenr]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=121</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	This is my screencast for the Nettuts/Screenr screencast competition. I feel as though I rushed it because I had to do it under 5 minutes but I hope you learn a thing or two from it. Source Files No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fsend-form-data-to-php-without-the-whole-page-reloading-using-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fsend-form-data-to-php-without-the-whole-page-reloading-using-jquery%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Send form data to PHP without the whole page reloading using jQuery" alt=" Send form data to PHP without the whole page reloading using jQuery" /><br />
			</a>
		</div>
<p>This is my screencast for the Nettuts/Screenr screencast competition. I feel as though I rushed it because I had to do it under 5 minutes but I hope you learn a thing or two from it.</p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_0817090731.swf' /><param name='flashvars' value='i=10656' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_0817090731.swf' flashvars='i=10656' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<p><a href="http://www.thetutorialblog.com/files/tutorials/jquery_form.zip">Source Files</a></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/send-form-data-to-php-without-the-whole-page-reloading-using-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

