<?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>Riot Riot &#187; PHP</title> <atom:link href="http://riotriot.net/category/design-development/php/feed/" rel="self" type="application/rss+xml" /><link>http://riotriot.net</link> <description></description> <lastBuildDate>Fri, 28 Oct 2011 17:33:16 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <atom:link rel="next" href="http://riotriot.net/category/design-development/php/feed/?page=2" /><item><title>PHP Classes and Functions</title><link>http://riotriot.net/2010/04/php-classes-and-functions/</link> <comments>http://riotriot.net/2010/04/php-classes-and-functions/#comments</comments> <pubDate>Tue, 27 Apr 2010 06:39:32 +0000</pubDate> <dc:creator>Jonathan</dc:creator> <category><![CDATA[Apple]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Tutorials]]></category><guid isPermaLink="false">http://riotriot.net/?p=1177</guid> <description><![CDATA[<a href="http://riotriot.net/2010/04/php-classes-and-functions/" title="PHP Classes and Functions"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1177&amp;w=180" width="1" height="1" alt="PHP Classes and Functions" style="float:left;padding:0 10px 10px 0;" ></a>PHP is a very powerful programming language which is favored more than many other languages when it comes to web functionality. In a personal viewpoint after learning functions and then on to classes you can start building much more advanced scripts and the only limit is your imagination. First lets get an basic understanding on [...]]]></description> <content:encoded><![CDATA[<a href="http://riotriot.net/2010/04/php-classes-and-functions/" title="PHP Classes and Functions"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1177&amp;w=180" width="1" height="1" alt="PHP Classes and Functions" style="float:left;padding:0 10px 10px 0;" ></a><p>PHP is a very powerful programming language which is favored more than many other languages when it comes to web functionality. In a personal viewpoint after learning functions and then on to classes you can start building much more advanced scripts and the only limit is your imagination.</p><p><span id="more-1177"></span></p><p>First lets get an basic understanding on how functions and classes work together. A class would refer to a &#8220;vehicle&#8221; in whole, and each function would be each &#8220;component&#8221; to make that vehicle run. Classes can not work correctly without functions, however you can run functions without a parent Class. Since this is the case, lets first build a function to see how they work.</p><blockquote><p>You can review more code snippits on <a href="http://www.xchristensen.com/code" target="_blank" title="PHP Code Examples">PHP Code Examples</a></p></blockquote><p>The only prerequisites needed to follow along with this tutorial would either be a server (online) or a offline &#8220;localhosted&#8221; service. If you would look for a easily deployable PHP install check out: <strong><a href="http://www.apachefriends.org">http://www.apachefriends.org</a></strong>. Their packages support: Linux, Windows and OSX.</p><p>After you have a enviroment to work in lets start off by <strong>creating a file in your server&#8217;s live directory called: &#8220;helloworld.php&#8221;</strong>. Then proceed to write some code as follows:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Lets build our function below! This is a basic print function  */</span>
<span style="color: #000000; font-weight: bold;">function</span> helloWorld<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'Hello everyone! Check out my small function!'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Now we will call our inline function and invoke the print! */</span>
helloWorld<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div><p>Granted that is very simple, but we need to start somewhere. Lets now more fancy and invoke some parameters to this function. You can <strong>either EDIT the previous file or create another, but lets modify some code to print some dynamic text.</strong></p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Lets build our function below! This is a basic print function  */</span>
<span style="color: #000000; font-weight: bold;">function</span> helloWorld<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'Hello everyone! My name is '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'. Check out my small function!'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Now we will call our inline function and invoke the print! */</span>
helloWorld<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Jonathan'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div><p>That following script should print out what ever is inside the &#8220;function call&#8221; which in our case is &#8220;Jonathan&#8221;. This again was very basic but can easily have IF ELSE statements, or other variables passed into a function. There is something to remember about functions, is that any items within the function can not be accessed from outside. Any internal variables are only accessible from within. Once familiar with building functions you will notice how much easier they turn code into. <strong>Lets see a real world use of a more complex function.</strong></p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* connect to a database */</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;db.inc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* build a mysql_query function that can be used multiple times without duplicating queries. */</span>
<span style="color: #000000; font-weight: bold;">function</span> query<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>	
&nbsp;
<span style="color: #666666; font-style: italic;">/* turn the query into a variable */</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM users&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* lets loop through the results and print a user name */</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">print</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div><p><strong>Lets now learn up on &#8220;classes&#8221;!</strong> Again this could be considered the whole &#8220;automobile&#8221; or full unit with all its functions. One example where i use classes would be for &#8220;database&#8221; functions. Anything that interacts with the database will be within that class.</p><p>First we would need to figure out what our class will be doing, for my particular instance we will be continuing the database &#8220;theme&#8221; and create a &#8220;database&#8221; class. <strong>Lets create a new file called &#8220;database.class.php&#8221; and put the following code:</strong></p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MySQLDB
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* connect to a database */</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;db.inc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* build a mysql_query function that can be used multiple times without duplicating queries. */</span>
	<span style="color: #000000; font-weight: bold;">function</span> query<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	  <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Create database connection */</span>
<span style="color: #000088;">$database</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MySQLDB<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div><p>Notice in the script the function &#8220;query&#8221; is not being executed anywhere in that snippit, the reason behind that is normally you would be including your &#8220;classes&#8221; into your documents rather than inline coding. This object oriented coding allows for you to break your code into &#8220;building blocks&#8221; which are easier to maintain. In our example you would be keeping all your database functions in one spot.</p><p><strong>Now, you can not just &#8220;call&#8221; the function by just typing:</strong> function query(); anymore. Now since its in a class you will now be using the line: <strong>$database->query();</strong> which again helps keep all your code more organized.</p><p>Hopefully this has helped some, and feel free to ask questions or help in regards to my code. I tried to stay simple but this can lead to a very hard and complicating subject.</p><p>IF you would like to know more and dont mind reading documentation please read up on:</p><p><strong>Functions: <a href="http://php.net/manual/en/language.functions.php" target="_blank">PHP &#8211; Functions</a></strong><br /> <strong>Classes &#038; Objects: <a href="http://php.net/manual/en/language.oop5.php" target="_blank">PHP &#8211; Classes &#038; Objects</a></strong></p> ]]></content:encoded> <wfw:commentRss>http://riotriot.net/2010/04/php-classes-and-functions/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Whats New in Drupal 7 Theming</title><link>http://riotriot.net/2010/04/whats-new-in-drupal-7-theming/</link> <comments>http://riotriot.net/2010/04/whats-new-in-drupal-7-theming/#comments</comments> <pubDate>Tue, 20 Apr 2010 22:02:11 +0000</pubDate> <dc:creator>Philip</dc:creator> <category><![CDATA[Design & Development]]></category> <category><![CDATA[Drupal]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Design]]></category> <category><![CDATA[DrupalCon]]></category> <category><![CDATA[Theming]]></category><guid isPermaLink="false">http://riotriot.net/?p=1107</guid> <description><![CDATA[<a href="http://riotriot.net/2010/04/whats-new-in-drupal-7-theming/" title="Whats New in Drupal 7 Theming"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1107&amp;w=180" width="1" height="1" alt="Whats New in Drupal 7 Theming" style="float:left;padding:0 10px 10px 0;" ></a>Some of my favorite new Drupal 7 theming &#8220;features&#8221;: jQuery UI is in Core! Neato. html.tpl.php &#8211; Granular theming of HTML. Pretty cool. hide() and render() functions Alter functions can now happen in template.php. Rrrrawesome.]]></description> <content:encoded><![CDATA[<a href="http://riotriot.net/2010/04/whats-new-in-drupal-7-theming/" title="Whats New in Drupal 7 Theming"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1107&amp;w=180" width="1" height="1" alt="Whats New in Drupal 7 Theming" style="float:left;padding:0 10px 10px 0;" ></a><p>Some of my favorite new Drupal 7 theming &#8220;features&#8221;:<span id="more-1107"></span></p><ul><li>jQuery UI is in Core! Neato.</li><li>html.tpl.php &#8211; Granular theming of HTML. Pretty cool.</li><li>hide() and render() functions</li><li>Alter functions can now happen in template.php. Rrrrawesome.</li></ul> ]]></content:encoded> <wfw:commentRss>http://riotriot.net/2010/04/whats-new-in-drupal-7-theming/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Collaberative Coding: How we work!</title><link>http://riotriot.net/2010/04/collaberative-coding-how-we-work/</link> <comments>http://riotriot.net/2010/04/collaberative-coding-how-we-work/#comments</comments> <pubDate>Fri, 16 Apr 2010 01:26:25 +0000</pubDate> <dc:creator>Jonathan</dc:creator> <category><![CDATA[Apple]]></category> <category><![CDATA[Misc.]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Coda]]></category> <category><![CDATA[Skype]]></category><guid isPermaLink="false">http://riotriot.net/?p=1039</guid> <description><![CDATA[<a href="http://riotriot.net/2010/04/collaberative-coding-how-we-work/" title="Collaberative Coding: How we work!"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1039&amp;w=180" width="1" height="1" alt="Collaberative Coding: How we work!" style="float:left;padding:0 10px 10px 0;" ></a>Ever work in sync with another co-worker on a particular program or file? If that&#8217;s so i&#8217;m sure you know some of the problems that can be run into. There is the potential chance of file over-writing or mistakenly deleting something that you should not have. Philip and I have both encountered this before when [...]]]></description> <content:encoded><![CDATA[<a href="http://riotriot.net/2010/04/collaberative-coding-how-we-work/" title="Collaberative Coding: How we work!"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1039&amp;w=180" width="1" height="1" alt="Collaberative Coding: How we work!" style="float:left;padding:0 10px 10px 0;" ></a><p>Ever work in sync with another co-worker on a particular program or file? If that&#8217;s so i&#8217;m sure you know some of the problems that can be run into. There is the potential chance of file over-writing or mistakenly deleting something that you should not have. Philip and I have both encountered this before when working on projects, and trust me after spending many hours on a particular section on a site then only to be saved over by accident by your partner almost makes you want to smash your head into the wall.</p><p><span id="more-1039"></span></p><p>This is where collaborative software comes into play, which we have been using constantly. Even more important is that we both can edit documents together if we have access to internet! This is crucial since we there are times when we are not physically next to each other. You are probably wondering what we have been using?</p><p><a href="http://panic.com/coda/" target="_blank">Panic&#8217;s <strong>CODA</strong></a>.<br /> <a href="http://riotriot.net/images/blog-images/coda-01.png" class="fancybox"><img src="http://riotriot.net/images/blog-images/coda-01.png" width="575px" /></a></p><p>Neither of us can really tell you have valuable this program is. Obviously you need to be running OSX to use this, but trust me when i say this program is FAST, Lightweight and reliable. Barely ever has this program crashed, and the functionality works flawlessly. Of course there are parts of CODA that i feel are missing but all-in-all they get 5 stars from us at (rr).</p><p><a href="http://riotriot.net/images/blog-images/coda-02png" class="fancybox"><img src="http://riotriot.net/images/blog-images/coda-02.png" class="fancybox" width="575px" /></a></p><p>If you are looking for some help with programming, CODA comes loaded with &#8220;books&#8221; to help programming! Most other programs do not supply help with code other than word/function suggestions. This becomes very helpful for new and experience programmers!</p><p><a href="http://riotriot.net/images/blog-images/coda-03.png" class="fancybox"><img src="http://riotriot.net/images/blog-images/coda-03.png" class="fancybox" width="575px" /></a></p><p><strong>Another tool&#8230;</strong> that has to be another key part in over-the-internet collaborative design would be iChat or Skype! This allows audio chat while coding through the same document! That ensures that nothing is missed or confused! It would almost be like working side by side even though we might be thousands of miles apart.</p><p><strong>The last tool&#8230;</strong> would probably be the use of google&#8217;s services weither it be DOCS or their email system. Its a free service, and quality so why not use whats available? Well there you have it, a little break down of Riot Riot&#8217;s design and development tools.</p> ]]></content:encoded> <wfw:commentRss>http://riotriot.net/2010/04/collaberative-coding-how-we-work/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Riot Riot Client Framework</title><link>http://riotriot.net/2010/02/riot-riot-client-framework/</link> <comments>http://riotriot.net/2010/02/riot-riot-client-framework/#comments</comments> <pubDate>Sat, 20 Feb 2010 01:41:30 +0000</pubDate> <dc:creator>Jonathan</dc:creator> <category><![CDATA[Design & Development]]></category> <category><![CDATA[PHP]]></category><guid isPermaLink="false">http://riotriot.net/?p=1026</guid> <description><![CDATA[<a href="http://riotriot.net/2010/02/riot-riot-client-framework/" title="Riot Riot Client Framework"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1026&amp;w=180" width="1" height="1" alt="Riot Riot Client Framework" style="float:left;padding:0 10px 10px 0;" ></a>Interwebs, mark today as the beginning of Riot Riot&#8217;s new adventure of using our framework! Today, we are beginning total development of our framework for any clients that jump on board. Both Phil and I are excited to start implementing any and all features we can imagine to help our clients understand the full scope [...]]]></description> <content:encoded><![CDATA[<a href="http://riotriot.net/2010/02/riot-riot-client-framework/" title="Riot Riot Client Framework"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1026&amp;w=180" width="1" height="1" alt="Riot Riot Client Framework" style="float:left;padding:0 10px 10px 0;" ></a><p>Interwebs, mark today as the beginning of Riot Riot&#8217;s new adventure of using our framework!</p><p><span id="more-1026"></span></p><p>Today, we are beginning total development of our framework for any clients that jump on board. Both Phil and I are excited to start implementing any and all features we can imagine to help our clients understand the full scope of work being built. Right now we just wanted to let everyone know that we will be spending spare time between projects further developing our application. Not only will this allow us to come up with fun new ideas but it will strengthen the framework for any clients that might require a lightweight CMS!</p><p>Keep an eye for any updates VIA twitter or through our blogs to see any new updates/pictures and content!</p> ]]></content:encoded> <wfw:commentRss>http://riotriot.net/2010/02/riot-riot-client-framework/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Simple PHP Progress Bar</title><link>http://riotriot.net/2010/02/simple-php-progress-bar/</link> <comments>http://riotriot.net/2010/02/simple-php-progress-bar/#comments</comments> <pubDate>Mon, 15 Feb 2010 03:55:38 +0000</pubDate> <dc:creator>Jonathan</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[HTML]]></category> <category><![CDATA[PHP]]></category><guid isPermaLink="false">http://riotriot.net/?p=1010</guid> <description><![CDATA[<a href="http://riotriot.net/2010/02/simple-php-progress-bar/" title="Simple PHP Progress Bar"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1010&amp;w=180" width="1" height="1" alt="Simple PHP Progress Bar" style="float:left;padding:0 10px 10px 0;" ></a>The other day i was looking to create a simple progress bar for a test application. So this is what i came up with in. Keep in mind this is nothing super intelligent or sophisticated. Lets start by starting creating the function which will be used to create this progress bar. 1 2 3 4 [...]]]></description> <content:encoded><![CDATA[<a href="http://riotriot.net/2010/02/simple-php-progress-bar/" title="Simple PHP Progress Bar"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=1010&amp;w=180" width="1" height="1" alt="Simple PHP Progress Bar" style="float:left;padding:0 10px 10px 0;" ></a><p>The other day i was looking to create a simple progress bar for a test application. So this is what i came up with in. Keep in mind this is nothing super intelligent or sophisticated.<span id="more-1010"></span></p><ol class="listed-steps"><li><p>Lets start by starting creating the function which will be used to create this progress bar.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td 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;">function</span> progressBar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$percentage</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>progress-bar<span style="color: #000099; font-weight: bold;">\&quot;</span> class=<span style="color: #000099; font-weight: bold;">\&quot;</span>all-rounded<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>progress-bar-percentage<span style="color: #000099; font-weight: bold;">\&quot;</span> class=<span style="color: #000099; font-weight: bold;">\&quot;</span>all-rounded<span style="color: #000099; font-weight: bold;">\&quot;</span> style=<span style="color: #000099; font-weight: bold;">\&quot;</span>width: <span style="color: #006699; font-weight: bold;">$percentage</span>%<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$percentage</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$percentage</span>%&quot;</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;">print</span> <span style="color: #0000ff;">&quot;&lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>spacer<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&amp;nbsp;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div></p></li><li><p>Next lets give the Div&#8217;s some style.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.all-rounded</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>
    border-radius<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: #6666ff;">.spacer</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;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#progress-bar</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</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: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#cccccc</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#f2f2f2</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#progress-bar-percentage</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#3063A5</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: #933;">0px</span><span style="color: #00AA00;">;</span>
 	<span style="color: #000000; font-weight: bold;">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;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</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: #00AA00;">&#125;</span></pre></td></tr></table></div></p></li><li><p>Once the CSS has been set, to run this function we just need to throw the function where you want to display it! <strong>Change the number inside the function to display a different percentage value.</strong></p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> progressBar<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div></p></li><li><p> Keep in mind you can use some MySQL queries to dynamically change the progress bar. This can be combined with other calculating formula&#8217;s also if you would really want this to be effective.</li></ul><blockquote><p>You can review more code snippits on <a href="http://www.xchristensen.com/code" target="_blank" title="PHP Code Examples">PHP Code Examples</a></p></blockquote> ]]></content:encoded> <wfw:commentRss>http://riotriot.net/2010/02/simple-php-progress-bar/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Flickr API and PHP, display images!</title><link>http://riotriot.net/2010/02/flickr-api-and-php-display-images/</link> <comments>http://riotriot.net/2010/02/flickr-api-and-php-display-images/#comments</comments> <pubDate>Tue, 09 Feb 2010 00:33:13 +0000</pubDate> <dc:creator>Jonathan</dc:creator> <category><![CDATA[HTML]]></category> <category><![CDATA[Misc.]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Tutorials]]></category><guid isPermaLink="false">http://riotriot.net/?p=942</guid> <description><![CDATA[<a href="http://riotriot.net/2010/02/flickr-api-and-php-display-images/" title="Flickr API and PHP, display images!"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=942&amp;w=180" width="1" height="1" alt="Flickr API and PHP, display images!" style="float:left;padding:0 10px 10px 0;" ></a>Flickr in the past couple years has really turned into a great service. PHP too has been a vital item to internet development! Now lets make them play nice together to grab some of your recent images in your flikr account! The first step to get this working is to create a Flickr account. Once [...]]]></description> <content:encoded><![CDATA[<a href="http://riotriot.net/2010/02/flickr-api-and-php-display-images/" title="Flickr API and PHP, display images!"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=942&amp;w=180" width="1" height="1" alt="Flickr API and PHP, display images!" style="float:left;padding:0 10px 10px 0;" ></a><p>Flickr in the past couple years has really turned into a great service. PHP too has been a vital item to internet development! Now lets make them play nice together to grab some of your recent images in your flikr account! <span id="more-942"></span></p><ol class="listed-steps"><li><p>The first step to get this working is to create a Flickr account.</p></li><li><p>Once your account is created, get a API. You can do that by clicking this link: <a href="http://www.flickr.com/services/apps/create/apply/" alt="Flickr API">Create a Flickr API</a>. It should be a 32 character (number and letter) random combination. This will be <strong>YOUR</strong> API so keep that somewhere easy to get to.</p></li><li><p>At this point open your favorite development program (for me, CODA or Espresso) and FTP client. <strong>Create the file: <u>flickr.class.php</u> and apply the following code:</strong></p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td 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> flickr <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> flickr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span><span style="color: #000088;">$api_key</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;">username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api_key</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$api_key</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_id</span>  <span style="color: #339933;">=</span> <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;">response</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>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeout</span>  <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> getUserId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.flickr.com/services/rest/?api_key='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api_key</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;method=flickr.urls.lookupUser&amp;url=http://www.flickr.com/photos/'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> getImages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.flickr.com/services/rest/?api_key='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api_key</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;method=flickr.photos.search&amp;user_id='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUserId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;per_page='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</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> fetch<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #000088;">$post</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;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_NOBODY<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #0000ff;">'Flickr'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</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;">response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_getinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'http_code'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</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: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div><p>The above code will be complicating if you do not understand <a href="http://www.php.net/manual/en/language.oop5.php" target="_blank">PHP Classes and Functions</a>. Hopefully you do understand enough of the syntax to breakdown some of the code.</p></li><li><p>Next, enter into a page where you would want to display your photos! This is some example code, make sure your &#8220;flickr.class.php&#8221; require is looking at the correct location. After setting that, <strong>change where it says: &#8220;username&#8221; and &#8220;your-api-key&#8221;.</strong></p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'flickr.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000088;">$flickr</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> flickr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'your-api-key'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$images</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$flickr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getImages</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</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: #b1b100;">echo</span> <span style="color: #0000ff;">'Flickr Feed Unavailable'</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;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">photos</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">photo</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;http://flickr.com/photos/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$flickr</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;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;&lt;img src=&quot;http://farm'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">farm</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.static.flickr.com/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">secret</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_s.jpg&quot; /&gt;&lt;/a&gt; '</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></td></tr></table></div></p></li><li><p>Save your files and then take it for a test drive!</p></li></ol> ]]></content:encoded> <wfw:commentRss>http://riotriot.net/2010/02/flickr-api-and-php-display-images/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>PHP &amp; MySQL Query Result Loops</title><link>http://riotriot.net/2010/01/php-mysql-query-result-loops/</link> <comments>http://riotriot.net/2010/01/php-mysql-query-result-loops/#comments</comments> <pubDate>Tue, 26 Jan 2010 04:49:34 +0000</pubDate> <dc:creator>Jonathan</dc:creator> <category><![CDATA[Design & Development]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[Query]]></category><guid isPermaLink="false">http://riotriot.net/?p=707</guid> <description><![CDATA[<a href="http://riotriot.net/2010/01/php-mysql-query-result-loops/" title="PHP &#038; MySQL Query Result Loops"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=707&amp;w=180" width="1" height="1" alt="PHP &#038; MySQL Query Result Loops" style="float:left;padding:0 10px 10px 0;" ></a>Static content is dying, but dynamic sites are emerging left and right. Lets focus on using PHP and merge it with mySQL so we can pull some dynamic data! The items needed in-order to make this tutorial work would be: PHP 4+ mySQL 4+ Access to admin in the mySQL database FTP program (if working [...]]]></description> <content:encoded><![CDATA[<a href="http://riotriot.net/2010/01/php-mysql-query-result-loops/" title="PHP &#038; MySQL Query Result Loops"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=707&amp;w=180" width="1" height="1" alt="PHP &#038; MySQL Query Result Loops" style="float:left;padding:0 10px 10px 0;" ></a><p>Static content is dying, but dynamic sites are emerging left and right. Lets focus on using <strong>PHP</strong> and merge it with <strong>mySQL</strong> so we can pull some dynamic data!</p><p><span id="more-707"></span><br /> The items needed in-order to make this tutorial work would be:</p><ul><li>PHP 4+</li><li>mySQL 4+</li><li>Access to admin in the mySQL database</li><li>FTP program (if working remotely)</li><li>Basic knowledge of syntax</li></ul><ol class="listed-steps"><li><p>First, lets begin with developing the database. This will require creating a new database if you do not already have one available. <strong>Let&#8217;s create a database called: <u>example</u></strong>.</p></li><li><p>Once the database is created, we will then need to <strong>create a table inside the database called: <u>records</u></strong>. Below is a example SQL code to use:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td 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;">'example'</span><span style="color: #66cc66;">.</span> <span style="color: #ff0000;">'records'</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">'id'</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">5</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: #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;">'name'</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">25</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;">'email'</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">255</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> MYISAM</pre></td></tr></table></div><p>The following code will create <strong>3</strong> columns in the database: <strong>id (int / 5 characters)</strong>, <strong>name (varChar / 25 characters)</strong>, and <strong>email (varChar / 100 characters)</strong>.  Setting <strong>id</strong> to &#8220;auto increment&#8221; means it will automatically come up with a new row-number as they are injected. This will allow us later on to pull specific records using this <strong>id</strong> field.</p></li><li><p>Next, lets <strong>begin with creating our first file: <u>db.inc.php</u></strong>. This will house our connection to the database, please be sure to use your own mySQL logins.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$hostname</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_login</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_password</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;yourpass&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$database</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;example&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hostname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_login</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Can't connect to mysql.&quot;</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$database</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Can't connect to db.&quot;</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></td></tr></table></div><p>The code there is somewhat more advanced, and too much to go over (im taking for granted you know some basic html/mysql commands).</p></li><li><p>Now lets create the file that will be pulling the data and listing the resulting data! <strong>Create the file: <u>results.php</u></strong> in the same folder as &#8220;db.inc.php&#8221;. In that file it will have:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM records&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>row<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$row[name]</span> | <span style="color: #006699; font-weight: bold;">$row[email]</span>&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div><p>After we required the &#8220;database&#8221; connection file, we then started to code our mySQL &#8220;<strong>query&#8221;</strong>: <u>SELECT * FROM records</u>. The asterisk means it will pull all the columns from the database.</p><p>We are then running the mySQL command &#8220;mysql_query&#8221; which will run that command through the database and grab all the rows and throws them into a array! Once it has them all, it stores them into that variable &#8220;<strong>$result</strong>&#8221; for later use in our application.</p><p>PHP&#8217;s &#8220;<strong>while</strong>&#8221; function is very valuable. It will repeat itself as long as there is records, once it runs out it will stop looping. As you can see in the code, it is looping the DIV &#8220;row&#8221; each time. Inside that DIV you see two php &#8220;variables&#8221;: <strong>$row[name]</strong> and <strong>$row[email]</strong>. The item that is inside the bracket is the &#8220;column&#8221; in the database. As said earlier, each row has been turned into an array, here is it turned into a usable item.</p></li><li><p>Last step is to return to your database program, and create a few records. <strong>If you want to just &#8220;inject&#8221; some SQL please use this:</strong></p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span>  <span style="color: #ff0000;">'example'</span><span style="color: #66cc66;">.</span> <span style="color: #ff0000;">'records'</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">'id'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">'name'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">'email'</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>  <span style="color: #ff0000;">'jonathan'</span><span style="color: #66cc66;">,</span>  <span style="color: #ff0000;">'youremail@email.com'</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div></p></li></ol> ]]></content:encoded> <wfw:commentRss>http://riotriot.net/2010/01/php-mysql-query-result-loops/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Test Multiple MAMP Vhosts With Parallels XP</title><link>http://riotriot.net/2009/08/test-multiple-mamp-vhosts-with-parallels-xp/</link> <comments>http://riotriot.net/2009/08/test-multiple-mamp-vhosts-with-parallels-xp/#comments</comments> <pubDate>Mon, 10 Aug 2009 02:51:41 +0000</pubDate> <dc:creator>Philip</dc:creator> <category><![CDATA[Apple]]></category> <category><![CDATA[Hosting]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Windows]]></category> <category><![CDATA[Apache]]></category> <category><![CDATA[MAMP]]></category> <category><![CDATA[Parallels]]></category> <category><![CDATA[Windows XP]]></category> <category><![CDATA[XP]]></category><guid isPermaLink="false">http://riotriot.net/?p=9</guid> <description><![CDATA[<a href="http://riotriot.net/2009/08/test-multiple-mamp-vhosts-with-parallels-xp/" title="Test Multiple MAMP Vhosts With Parallels XP"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=9&amp;w=180" width="1" height="1" alt="Test Multiple MAMP Vhosts With Parallels XP" style="float:left;padding:0 10px 10px 0;" ></a>This tutorial is based on the presumption that you have successfully installed MAMP on your Mac and are running multiple vhosts. If you have not done this yet, please see this link. What I&#8217;m Working With 15&#8243; MacBook Pro OS X 10.5.7 MAMP 1.4.1 (Default MAMP Port Settings) Parallels 4.0.3844 Windows XP SP3 Step 1: [...]]]></description> <content:encoded><![CDATA[<a href="http://riotriot.net/2009/08/test-multiple-mamp-vhosts-with-parallels-xp/" title="Test Multiple MAMP Vhosts With Parallels XP"><img src="http://riotriot.net/wordpress/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=9&amp;w=180" width="1" height="1" alt="Test Multiple MAMP Vhosts With Parallels XP" style="float:left;padding:0 10px 10px 0;" ></a><p>This tutorial is based on the presumption that you have successfully installed <a href="http://www.mamp.info/en/mamp/index.html" target="_blank">MAMP</a> on your Mac and are running multiple vhosts. If you have not done this yet, please see this <a href="http://tinyurl.com/ktgzn3" target="_blank">link</a>.<span id="more-9"></span><br /><h3>What I&#8217;m Working With</h3><ul><li>15&#8243; MacBook Pro</li><li>OS X 10.5.7</li><li>MAMP 1.4.1 (Default MAMP Port Settings)</li><li>Parallels 4.0.3844</li><li>Windows XP SP3</li></ul><p> <strong>Step 1:</strong> Go into the Mac&#8217;s System Preferences. Choose Network, and select Parallels Host-Only Network. Copy the IP address here as you will use it for the Windows XP Hosts file. <a href="http://blog.riotriot.net/wp-content/uploads/2009/08/network-settings1.jpg"><img class="wp-image-29 aligncenter" title="network-settings1" src="http://blog.riotriot.net/wp-content/uploads/2009/08/network-settings1.jpg" alt="" width="575" /></a> <strong>Step 2:</strong> Locate and open (with Notepad or another text editor of your choice) your Hosts file for Windows XP. It should be in C:\WINDOWS\system32\drivers\etc. Add the aliases and Host-Only IP you copied address like so (I used the same aliases that I used on my Mac): <a href="http://blog.riotriot.net/wp-content/uploads/2009/08/xp-hosts.jpg"><img class="wp-image-27 aligncenter" title="xp-hosts" src="http://blog.riotriot.net/wp-content/uploads/2009/08/xp-hosts.jpg" alt="" width="575" /></a> <strong>Step 3:</strong> Change the Parallels network setting to Host-Only Networking. <a href="http://blog.riotriot.net/wp-content/uploads/2009/08/parallels-network.jpg"><img class="wp-image-30 aligncenter" title="parallels-network" src="http://blog.riotriot.net/wp-content/uploads/2009/08/parallels-network.jpg" alt="" width="575" /></a> <strong>Finishing: </strong> Ok, everything is configured. Use the alias for the site you want to view in Internet Explorer: http://mysweetsite.local:8888/ and hit enter ;)</p> ]]></content:encoded> <wfw:commentRss>http://riotriot.net/2009/08/test-multiple-mamp-vhosts-with-parallels-xp/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 9/63 queries in 0.090 seconds using disk: basic
Object Caching 1175/1320 objects using disk: basic

Served from: riotriot.net @ 2012-05-20 08:49:33 -->
