<?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>Server Side Guy &#187; PHP</title>
	<atom:link href="http://serversideguy.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://serversideguy.com</link>
	<description>Just another Barsness Solutions weblog</description>
	<lastBuildDate>Tue, 31 Jan 2012 14:57:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Looping through Mysql Columns</title>
		<link>http://serversideguy.com/2009/10/05/looping-through-mysql-columns/</link>
		<comments>http://serversideguy.com/2009/10/05/looping-through-mysql-columns/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 16:36:35 +0000</pubDate>
		<dc:creator>Andy Stramer</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=148</guid>
		<description><![CDATA[Recently I was looking into a way to echo out each column name of a mysql database. Of course I needed to do it dynamically as the database could change and the application is in PHP. First the Query: $col_query = &#34;SHOW COLUMNS FROM `your_tablename`&#34;; $col_res = mysql_query&#40;$col_query&#41; or die&#40;mysql_error&#40;&#41;&#41;; This query result will return [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was looking into a way to echo out each column name of a mysql database. Of course I needed to do it dynamically as the database could change and the application is in PHP.</p>
<p>First the Query:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">$col_query <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;SHOW COLUMNS FROM `your<span style="color: #008080; font-weight: bold;">_</span>tablename`&quot;</span><span style="color: #000033;">;</span>
$col_res <span style="color: #CC0099;">=</span> mysql_query<span style="color: #FF00FF;">&#40;</span>$col_query<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">or</span> die<span style="color: #FF00FF;">&#40;</span>mysql_error<span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p>This query result will return an array of the columns. There are a few keys to the array to point out. Field is your column name. Type is the data type. Others include Null, Key, Default, and Extra.  So to get the results I&#8217;ve been looking for I had to add the following PHP code.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$col_query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SHOW COLUMNS FROM `your_tablename`&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$col_res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$col_query</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Here is what I needed to add</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$col</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$col_res</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$col</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Field'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This little snippet of code can make life easier if you are displaying data in a database dynamically.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/10/05/looping-through-mysql-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Growl from PHP</title>
		<link>http://serversideguy.com/2009/07/29/growl-from-php/</link>
		<comments>http://serversideguy.com/2009/07/29/growl-from-php/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 22:30:04 +0000</pubDate>
		<dc:creator>Tim Barsness</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Growl]]></category>
		<category><![CDATA[PHP Class]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=59</guid>
		<description><![CDATA[I just found this nifty PHP class for sending growl notifications from sitecrafting.com.  Very nifty.  Here&#8217;s some sample code to get it going: // Setup $growl = new Growl&#40;&#41;; $growl-&#62;setAddress&#40;'127.0.0.1'&#41;; $growl-&#62;addNotification&#40;&#34;Test&#34;&#41;; $growl-&#62;register&#40;&#41;; &#160; // Send Notification $growl-&#62;notify&#40;&#34;Test&#34;, &#34;Test Alert&#34;, &#34;The body of the test alert!&#34;&#41;;]]></description>
			<content:encoded><![CDATA[<p>I just found <a href="http://www.sitecrafting.com/blog/php-growl/" target="_blank">this</a> nifty PHP class for sending growl notifications from <a href="http://www.sitecrafting.com" target="_blank">sitecrafting.com</a>.  Very nifty.  Here&#8217;s some sample code to get it going:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Setup</span>
<span style="color: #000088;">$growl</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Growl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$growl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAddress</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$growl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addNotification</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Test&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$growl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</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;">// Send Notification</span>
<span style="color: #000088;">$growl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">notify</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Test&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Test Alert&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;The body of the test alert!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/07/29/growl-from-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate Random Strings in PHP</title>
		<link>http://serversideguy.com/2009/05/11/generate-random-strings-in-php/</link>
		<comments>http://serversideguy.com/2009/05/11/generate-random-strings-in-php/#comments</comments>
		<pubDate>Mon, 11 May 2009 21:01:50 +0000</pubDate>
		<dc:creator>Tim Barsness</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[iterative]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[random string]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=11</guid>
		<description><![CDATA[I needed to generate some random strings today for password resets.  Here&#8217;s what I used: function genRandomString&#40;$length = 10&#41; &#123; $characters = ‘0123456789abcdefghijklmnopqrstuvwxyz’; $string = ”; &#160; for &#40;$p = 0; $p &#60; $length; $p++&#41; &#123; $string .= $characters&#91;mt_rand&#40;0, strlen&#40;$characters&#41;&#41;&#93;; &#125; &#160; return $string; &#125; Or, recursively: function genRandomString&#40;$i, $length = 10&#41; &#123; $characters = [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to generate some random strings today for password resets.  Here&#8217;s what I used:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> genRandomString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$characters</span> <span style="color: #339933;">=</span> ‘0123456789abcdefghijklmnopqrstuvwxyz’<span style="color: #339933;">;</span>
   <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> ”<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$p</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$length</span><span style="color: #339933;">;</span> <span style="color: #000088;">$p</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$characters</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">mt_rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$characters</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Or, recursively:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> genRandomString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$characters</span> <span style="color: #339933;">=</span> ‘0123456789abcdefghijklmnopqrstuvwxyz’<span style="color: #339933;">;</span>
   <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> ”<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$characters</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">mt_rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$characters</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>genRandomString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/05/11/generate-random-strings-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

