<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: php code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 06 Oct 2008 12:49:41 GMT</pubDate>
    <description>DZone Snippets: php code</description>
    <item>
      <title>Run a simple Update Query</title>
      <link>http://snippets.dzone.com/posts/show/3907</link>
      <description>In PHP.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$result = mysql_query("UPDATE example SET age='22' WHERE age='21'") &lt;br /&gt;or die(mysql_error());  &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 26 Apr 2007 11:48:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3907</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>Generate a dropdown with months in a year</title>
      <link>http://snippets.dzone.com/posts/show/2507</link>
      <description>The below code will generate a form dropdown for all 12 months, with the current month selected. Handy for those date pickers!&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;select name="start_month"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;global $LOC;&lt;br /&gt;$current_time_m = $LOC-&gt;decode_date('%m', $LOC-&gt;now);&lt;br /&gt;&lt;br /&gt;for ($i = 1; $i &lt;= 12; $i++) {&lt;br /&gt;   echo "&lt;option value='$i-'";&lt;br /&gt;if ($i == $current_time_m) { echo " selected='selected'"; }&lt;br /&gt;$month_text = date("F", mktime(0, 0, 0, $i+1, 0, 0, 0));&lt;br /&gt;   echo "&gt;$month_text&lt;/option&gt;&lt;br /&gt;"; } ?&gt;&lt;br /&gt;&lt;/select&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Aug 2006 17:08:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2507</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>Generate a dropdown with days of the month</title>
      <link>http://snippets.dzone.com/posts/show/2506</link>
      <description>The below code will generate a form dropdown for all the days of the month, with today's day selected. Handy for those date pickers!&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;select name="start_day"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;global $LOC;&lt;br /&gt;$current_time_day = $LOC-&gt;decode_date('%d', $LOC-&gt;now);&lt;br /&gt;&lt;br /&gt;for ($i = 1; $i &lt;= 31; $i++) {&lt;br /&gt;   echo "&lt;option value='$i'";&lt;br /&gt;if ($i == $current_time_day) { echo " selected='selected'"; }&lt;br /&gt;   echo "&gt;$i&lt;/option&gt;&lt;br /&gt;";&lt;br /&gt;} ?&gt;&lt;br /&gt;&lt;/select&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Aug 2006 17:06:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2506</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>Loop in PHP Using For (Descending)</title>
      <link>http://snippets.dzone.com/posts/show/2219</link>
      <description>For those times you need to do a loop in PHP, but have the outcome be in descending order (ie, start at 10 and end at 1).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$totalcode="10";&lt;br /&gt;for($i=$totalcode; $i&gt;0; $i--){&lt;br /&gt;&lt;br /&gt; echo"$i";&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 20 Jun 2006 15:26:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2219</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>Loop in PHP Using For (Ascending)</title>
      <link>http://snippets.dzone.com/posts/show/2218</link>
      <description>If you have a set number of times you need to repeat a piece of coding, using the for loop is the easiest way to accomplish this.&lt;br /&gt;&lt;br /&gt;$i is the starting number, 1 in this case. This loop will repeat itself until $i reaches 10 - you can change this to any desired number. The bit inbetween the { and } is simply what is repeated - replace this with anything you want. :)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;for ($i = 1; $i &lt;= 10; $i++) {&lt;br /&gt;   echo $i;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 20 Jun 2006 15:25:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2218</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>Pad Numbers in PHP</title>
      <link>http://snippets.dzone.com/posts/show/2217</link>
      <description>Sometimes I need numbers to always be two digits, even if they're less than 10. The below snippet will format all numbers to be two digits, inserting a 0 if they're under 10 - creating, for example, 09 instead of 9.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$raw = 1;&lt;br /&gt;$formatted = sprintf("%02d", $raw);&lt;br /&gt;echo $formatted;&lt;br /&gt;&lt;br /&gt;//outputs 01&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 20 Jun 2006 15:20:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2217</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>Random Number</title>
      <link>http://snippets.dzone.com/posts/show/1257</link>
      <description>Replace 1 and 10 with the range you want to pick a number between. This example will pick a random number between 1 and 10.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$randomnumber= rand(1,10);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 21 Jan 2006 21:41:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1257</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>Display Current Year</title>
      <link>http://snippets.dzone.com/posts/show/1248</link>
      <description>Useful for example for automatic copyright notices:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;copy; Copyright 2004 - &lt;?php echo date("Y") ?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 21 Jan 2006 21:37:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1248</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>Date In The Future</title>
      <link>http://snippets.dzone.com/posts/show/1247</link>
      <description>How to display a date in the future - in this case, next month.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt; $nextmonth = mktime(0, 0, 0, date("m")+1, 1, date("Y"));&lt;br /&gt; echo date("F", $nextmonth);&lt;br /&gt; ?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 21 Jan 2006 21:36:41 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1247</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>Display In 2-Column Table</title>
      <link>http://snippets.dzone.com/posts/show/1244</link>
      <description>The below can be applied to MT, EE, etc, and will display the content in a 2 column table. The EE tags below are just an example, it will work equally well if you replace it with MT, Wordpress, etc, tags.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;? $set_table="0"; ?&gt;&lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="5" border="0"&gt;&lt;br /&gt;{exp:gallery:categories gallery="{gallery_name}"}&lt;br /&gt;&lt;? &lt;br /&gt;$set_table = $set_table +1;&lt;br /&gt;if ($set_table == "1") {echo"&lt;tr&gt;";} ?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Insert other tags here.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;? if ($set_table == "2") {echo"&lt;/tr&gt;";  $set_table="0";} ?&gt;&lt;br /&gt;{/exp:gallery:categories}&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 21 Jan 2006 21:35:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1244</guid>
      <author>nothingless (Sasha)</author>
    </item>
  </channel>
</rss>
