
<?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>jtGraphic.net &#187; Programming</title>
	<atom:link href="http://jtgraphic.net/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://jtgraphic.net</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 01:15:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Be lazy naming your next info product.</title>
		<link>http://jtgraphic.net/lazy-naming-info-product/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lazy-naming-info-product</link>
		<comments>http://jtgraphic.net/lazy-naming-info-product/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 23:44:45 +0000</pubDate>
		<dc:creator>jt</dc:creator>
				<category><![CDATA[Marketing]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Info Products]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://www.jtgraphic.net/?p=734</guid>
		<description><![CDATA[<p>Tweet If you need help naming your next info product, check this out: www.infoproductnamer.com Basically it&#8217;s to help you be lazy.  You can create your next info product name easily.  If you don&#8217;t even know what you want your info &#8230; <a href="http://jtgraphic.net/lazy-naming-info-product/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/lazy-naming-info-product/">Be lazy naming your next info product.</a></p>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Flazy-naming-info-product%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/lazy-naming-info-product/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/lazy-naming-info-product/"  data-text="Be lazy naming your next info product." data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/lazy-naming-info-product/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/lazy-naming-info-product/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>If you need help naming your next info product, check this out:</p>
<p><a href="http://www.infoproductnamer.com/index.htm?niche=Cash&amp;f=11&amp;s=0" target="_blank">www.infoproductnamer.com</a></p>
<p>Basically it&#8217;s to help you be lazy.  You can create your next info product name easily.  If you don&#8217;t even know what you want your info product to be, it can help you with that too.  It comes preloaded with many different niches for you to try out, or you can enter your own.  All of this value completely free!</p>
<p>The product is currently in beta and accepting feature requests.</p>
<p>What do you think about it?</p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Flazy-naming-info-product%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/lazy-naming-info-product/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/lazy-naming-info-product/"  data-text="Be lazy naming your next info product." data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/lazy-naming-info-product/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/lazy-naming-info-product/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/lazy-naming-info-product/">Be lazy naming your next info product.</a></p>]]></content:encoded>
			<wfw:commentRss>http://jtgraphic.net/lazy-naming-info-product/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Automated Way to Find Google Pagerank</title>
		<link>http://jtgraphic.net/automated-find-google-pagerank/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automated-find-google-pagerank</link>
		<comments>http://jtgraphic.net/automated-find-google-pagerank/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 21:11:41 +0000</pubDate>
		<dc:creator>jt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Pagerank]]></category>
		<category><![CDATA[Program]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[Tidbit Tuesday]]></category>

		<guid isPermaLink="false">http://www.jtgraphic.net/?p=722</guid>
		<description><![CDATA[<p>Tweet I was looking for an automated way to get Google Pagerank for a few hours and came up with quite a few things, but not many of them were very elegant.  Essentially, Google doesn&#8217;t provide an API and it&#8217;s &#8230; <a href="http://jtgraphic.net/automated-find-google-pagerank/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/automated-find-google-pagerank/">Automated Way to Find Google Pagerank</a></p>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fautomated-find-google-pagerank%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/automated-find-google-pagerank/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/automated-find-google-pagerank/"  data-text="Automated Way to Find Google Pagerank" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/automated-find-google-pagerank/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/automated-find-google-pagerank/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>I was looking for an automated way to get Google Pagerank for a few hours and came up with quite a few things, but not many of them were very elegant.  Essentially, Google doesn&#8217;t provide an API and it&#8217;s against their terms of service to hit them up in an automated way.  I found quite a few places that have come up with close algorithms and calculate PR for sites, but that&#8217;s just not accurate enough for me.  The other option is to hit their PR URL that the toolbar uses.  For example:</p>
<p><a href="http://toolbarqueries.google.com/search?client=navclient-auto&amp;hl=en&amp;ch=61470319184&amp;ie=UTF-8&amp;oe=UTF-8&amp;features=Rank&amp;q=info:http%3A%2F%2Fforums.digitalpoint.com%2Fshowthread.php%3Ft%3D164713" target="_blank">http://toolbarqueries.google.com/search?client=navclient-auto&amp;hl=en&amp;ch=61470319184&amp;ie=UTF-8&amp;oe=UTF-8&amp;features=Rank&amp;q=info:http%3A%2F%2Fforums.digitalpoint.com%2Fshowthread.php%3Ft%3D164713</a></p>
<p>That returns the PR of Digital Point Forums, where I found that information, but you can&#8217;t change the reference URL, because of a checksum.  That&#8217;s the &amp;ch= variable in the URL.  I&#8217;m working on a project that needs to look up PR on the fly though, so that just won&#8217;t work.  I ended up finding a script that I could use, but the guy didn&#8217;t put his URL in the comments, and I since can&#8217;t find it &#8211; oops.  I think he deserves a pat on the back though.  If this belongs to you, or you know who&#8217;s it is, let me know.</p>
<p>I tweaked the script and installed it on my <a href="http://toolerific.com" target="_blank">Toolerific.com</a> website.  Now you can go there and check the PR of any site without a captcha, which is nice.  The tool is <a href="http://toolerific.com/pagerankcheck/" target="_blank">here</a>.</p>
<p>Now, the best automated way to check pagerank is to hit that site with cURL and take out the value of the HTML tag with the id &#8220;value&#8221;.  The reason that is the best automated way to do it is because Google may change their checksum rules and that will break the source code that I used to generate it, but that site will always be laid out like that, so you don&#8217;t have to worry about changing anything.  If you want the code I used, you can view it <a href="http://www.jtgraphic.net/code/june-2010-pr-checker-php-script/">here</a>.</p>
<p><em><strong>Update</strong>: This doesn&#8217;t seem to work ALL of the time.  I suspect it has something to do with the checksum, but can&#8217;t figure it out.  Seems to be about 27% of the time, which isn&#8217;t great odds, but it works MOST of the time.  I&#8217;ll keep you posted if I find out more.</em></p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fautomated-find-google-pagerank%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/automated-find-google-pagerank/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/automated-find-google-pagerank/"  data-text="Automated Way to Find Google Pagerank" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/automated-find-google-pagerank/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/automated-find-google-pagerank/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/automated-find-google-pagerank/">Automated Way to Find Google Pagerank</a></p>]]></content:encoded>
			<wfw:commentRss>http://jtgraphic.net/automated-find-google-pagerank/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Head Tracking for 3D Gaming</title>
		<link>http://jtgraphic.net/head-tracking-3d-gaming/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=head-tracking-3d-gaming</link>
		<comments>http://jtgraphic.net/head-tracking-3d-gaming/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 02:26:36 +0000</pubDate>
		<dc:creator>jt</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Gaming]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Wii]]></category>

		<guid isPermaLink="false">http://www.jtgraphic.net/?p=649</guid>
		<description><![CDATA[<p>Tweet Found out about this on Oliver Ames&#8217;s blog.  I think this will be the next big evolution in gaming and movies.  This technology is amazing.  Unfortunately it only works for one person, but maybe some day we will be &#8230; <a href="http://jtgraphic.net/head-tracking-3d-gaming/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/head-tracking-3d-gaming/">Head Tracking for 3D Gaming</a></p>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fhead-tracking-3d-gaming%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/head-tracking-3d-gaming/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/head-tracking-3d-gaming/"  data-text="Head Tracking for 3D Gaming" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/head-tracking-3d-gaming/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/head-tracking-3d-gaming/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p style="text-align: center">
<p style="text-align: left">Found out about this on<a href="http://www.oliverames.me/head-tracking-for-desktop-vr-displays-using-t-25" target="_blank"> Oliver Ames&#8217;s</a> blog.  I think this will be the next big evolution in gaming and movies.  This technology is amazing.  Unfortunately it only works for one person, but maybe some day we will be able to broadcast on multiple channels through a TV to these headsets similar to how 3D movies work now.</p>
<p style="text-align: left">What do you think about it?</p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fhead-tracking-3d-gaming%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/head-tracking-3d-gaming/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/head-tracking-3d-gaming/"  data-text="Head Tracking for 3D Gaming" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/head-tracking-3d-gaming/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/head-tracking-3d-gaming/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/head-tracking-3d-gaming/">Head Tracking for 3D Gaming</a></p>]]></content:encoded>
			<wfw:commentRss>http://jtgraphic.net/head-tracking-3d-gaming/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tidbit Tuesday on PHP: Simple MySQL Database Insert Function</title>
		<link>http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tidbit-tuesday-php-simple-mysql-database-insert-function</link>
		<comments>http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 19:03:49 +0000</pubDate>
		<dc:creator>jt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[How]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[return]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[Tidbit Tuesday]]></category>

		<guid isPermaLink="false">http://www.jtgraphic.net/?p=460</guid>
		<description><![CDATA[<p>Tweet This builds on a function I did last week: db_query(). You can send any array straight to a MySQL database and it&#8217;ll even check to make sure the column actually exists.  Oh, and it returns the id of the &#8230; <a href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/">Tidbit Tuesday on PHP: Simple MySQL Database Insert Function</a></p>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Ftidbit-tuesday-php-simple-mysql-database-insert-function%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/"  data-text="Tidbit Tuesday on PHP: Simple MySQL Database Insert Function" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>This builds on a function I did last week: <a href="http://www.jtgraphic.net/2009/11/tidbit-tuesday-php-simple-mysql-database-query-function/" target="_blank">db_query()</a>.  You can send any array straight to a MySQL database and it&#8217;ll even check to make sure the column actually exists.  Oh, and it returns the id of the record you just added in case you needed it.</p>
<pre>&lt;?php
   function db_array_insert($cfg_array, $table, $array) {
      require_once("dbQuery.function");

      $sql = "show columns from ".$table
      $tableArray = db_query($cfg_array, $sql);
      $inputString = "";

      foreach($tableArray as $key =&gt; $value) {
         if (array_key_exists($value[0], $array) &amp;&amp; $value[0])
            $inputString .= "'".addslashes($array[$value[0]])."', ";
         else
            $inputString .= "'', ";
      }

      $inputString = substr($inputString, 0, -2);
      $sql = "insert into $table values(".$inputString.")"
      db_query($cfg_array, $sql);

      return mysql_insert_id();
   }

   $insert_array = array(
      "column_1" =&gt; "something_1",
      "column_2" =&gt; "something_2"
   );

   $cfg_array = array(
      "db_loc" =&gt; 'www.databaselocation.com',
      "db_user" =&gt; 'some user'
      "db_pass" =&gt; 'some password'
      "db_name" =&gt; 'database_name_here'
   );

   db_array_insert($cfg_array, "some_table", $insert_array); //and use it.
?&gt;
</pre>
<p>So what do you think?  Having a problem?  Just let me know in the comments.</p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Ftidbit-tuesday-php-simple-mysql-database-insert-function%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/"  data-text="Tidbit Tuesday on PHP: Simple MySQL Database Insert Function" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/">Tidbit Tuesday on PHP: Simple MySQL Database Insert Function</a></p>]]></content:encoded>
			<wfw:commentRss>http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-insert-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tidbit Tuesday on PHP: Simple MySQL Database Query Function</title>
		<link>http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tidbit-tuesday-php-simple-mysql-database-query-function</link>
		<comments>http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 17:28:20 +0000</pubDate>
		<dc:creator>jt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[db_query]]></category>
		<category><![CDATA[die]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql_connect]]></category>
		<category><![CDATA[mysql_error]]></category>
		<category><![CDATA[mysql_query]]></category>
		<category><![CDATA[mysql_select_db]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[Tidbit Tuesday]]></category>

		<guid isPermaLink="false">http://www.jtgraphic.net/?p=452</guid>
		<description><![CDATA[<p>Tweet It&#8217;s always great to create functions for those things you do a lot.  Probably the single most common function I execute is database calls. Here is a simple script for hitting up your MySQL database with a query: &#60;?php &#8230; <a href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/">Tidbit Tuesday on PHP: Simple MySQL Database Query Function</a></p>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Ftidbit-tuesday-php-simple-mysql-database-query-function%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/"  data-text="Tidbit Tuesday on PHP: Simple MySQL Database Query Function" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>It&#8217;s always great to create functions for those things you do a lot.  Probably the single most common function I execute is database calls.</p>
<p>Here is a simple script for hitting up your MySQL database with a query:</p>
<pre>
&lt;?php
   if(!function_exists(dbQuery)) {
      function db_query($cfg_array, $query) {
         $connection =
            mysql_connect(
               $cfg_array['db_loc'],$cfg_array['db_user'],$cfg_array['db_pass']
            ) or die(mysql_error());

         mysql_select_db($cfg_array['db_name'],$connection)
            or die(mysql_error()." &gt;&gt; ".$query);
         $result = mysql_query($query,$connection)
            or die (mysql_error()." &gt;&gt; ".$query);
         $i = 0;

         if($result != 1) {
            while ($data_array = mysql_fetch_array($result)) {
               foreach($data_array as $key =&gt; $value) {
                  $tableArray[$i][$key] = stripslashes($data_array[$key]);
               }

               $i++;
            }

            return $tableArray;
         }
      }
   }
?&gt;
</pre>
<p>You should be able to just copy and paste this as a function and call it in one of two ways:</p>
<pre>
$cfg_array = array(
   "db_loc" =&gt; 'www.databaselocation.com',
   "db_user" =&gt; 'some user'
   "db_pass" =&gt; 'some password'
   "db_name" =&gt; 'database_name_here'
);

$query = "SELECT * FROM 'table' WHERE some_column = 'something'";

db_query($cfg_array, $query); // This will return an array with the table in it.

$query = "UPDATE/DELETE/ETC * FROM 'table' WHERE some_column = 'something'";

db_query($cfg_array, $query); // This will return return an empty array, but still works.
</pre>
<p>I use this function in EVERYTHING.  I also have some other functions that use this as its base.  Someday I&#8217;ll turn it into a class.</p>
<p>So, what do you think?</p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Ftidbit-tuesday-php-simple-mysql-database-query-function%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/"  data-text="Tidbit Tuesday on PHP: Simple MySQL Database Query Function" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/">Tidbit Tuesday on PHP: Simple MySQL Database Query Function</a></p>]]></content:encoded>
			<wfw:commentRss>http://jtgraphic.net/tidbit-tuesday-php-simple-mysql-database-query-function/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tidbit Tuesday on PHP: Holiday Notices for Business Sites</title>
		<link>http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tidbit-tuesday-php-holiday-notices-business-sites</link>
		<comments>http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 20:47:48 +0000</pubDate>
		<dc:creator>jt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[2009]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Calendar]]></category>
		<category><![CDATA[Custom Functions]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[strtotime]]></category>
		<category><![CDATA[Tidbit Tuesday]]></category>

		<guid isPermaLink="false">http://www.jtgraphic.net/?p=343</guid>
		<description><![CDATA[<p>Tweet This is a handy script for managing an out of office message on your website.  I find this very useful on business websites when you&#8217;re tired of making that one little change to let people know when the office &#8230; <a href="http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/">Tidbit Tuesday on PHP: Holiday Notices for Business Sites</a></p>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Ftidbit-tuesday-php-holiday-notices-business-sites%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/"  data-text="Tidbit Tuesday on PHP: Holiday Notices for Business Sites" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>This is a handy script for managing an out of office message on your website.  I find this very useful on business websites when you&#8217;re tired of making that one little change to let people know when the office will be shut down.  With about 15 minutes of extra work, you only need to do it once a year.</p>
<p>Let&#8217;s say for instance we&#8217;re doing all of the major U.S. Holidays in 2010, observing weekend Holidays with a day off on either side of the weekend.  This means first we need to determine what those dates are.  I just happen to have looked up the six most common, listed below:</p>
<ul>
<li>New Year&#8217;s Eve &#8211; January 1st</li>
<li>Memorial Day &#8211; May 31st</li>
<li>Independence Day &#8211; July 5th (July 4th is Sunday)</li>
<li>Labor Day &#8211; September 6th</li>
<li>Thanksgiving &#8211; November 25th and 26th</li>
<li>Christmas &#8211; December 24th (December 25th is a Saturday)</li>
</ul>
<p>Now that we know our dates, we can build them into an array:</p>
<pre>$date_array = array(
   "New Yearís Eve" =&gt;
      array("leaving" =&gt; "2010-12-31", "returning" =&gt; "2011-01-03"),
   "Memorial Day" =&gt;
      array("leaving" =&gt; "2010-05-31", "returning" =&gt; "2010-06-01"),
   "Independence Day" =&gt; // July 4th is a Sunday
      array("leaving" =&gt; "2010-07-05", "returning" =&gt; "2010-07-06"),
   "Labor Day" =&gt;
      array("leaving" =&gt; "2010-09-06", "returning" =&gt; "2010-09-07"),
   "Thanksgiving" =&gt;
      array("leaving" =&gt; "2010-11-025", "returning" =&gt; "2010-11-029"),
   "Christmas" =&gt; // December 25th is a Saturday
      array("leaving" =&gt; "2010-12-24", "returning" =&gt; "2010-12-27"),
 );</pre>
<p>The date array can easily be stored in a database or be made up of more complicated functions that would calculate the holidays across multiple years with some basic logic.  Maybe we&#8217;ll cover the latter part in another post some day.</p>
<p>Now we need to build the function itself.  This function will be run every time the page loads.  You can even include the function in a separate file to be included on multiple pages:</p>
<pre>function holiday_message($date, $date_array) {
   $date = strtotime($date); // Reformat the date so we can do math on it.
   foreach($date_array as $key =&gt; $value) {
      $leaving = strtotime($value['leaving']);
      $returning = strtotime($value['returning']);
      $early_warning = $leaving - 86400 * 7;
      // If the date is between (7 days before) leaving and returning
         if($date &gt; $early_warning &amp;&amp; $date &lt; $returning) {
            echo
               "We will be observing ".$key." from ".date("Y-m-d", $leaving).
               " until ". date("Y-m-d", $returning).".
               When we return we will be more than happy to assist you.";
         }
   }
}</pre>
<p>Now we just need to execute this function anywhere on the page:</p>
<pre>holiday_message(date("Y-m-d H:i:s"),$date_array);</pre>
<p>This code can be customized in numerous different ways, so the the message is more formal, or works for your specific situation.  You can also change the way days are stored or calculated, like the example above.  This is a core to get you started.  Where can you go from here?</p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Ftidbit-tuesday-php-holiday-notices-business-sites%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/"  data-text="Tidbit Tuesday on PHP: Holiday Notices for Business Sites" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/">Tidbit Tuesday on PHP: Holiday Notices for Business Sites</a></p>]]></content:encoded>
			<wfw:commentRss>http://jtgraphic.net/tidbit-tuesday-php-holiday-notices-business-sites/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP Function Friday: function</title>
		<link>http://jtgraphic.net/php-function-friday-function/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-function-friday-function</link>
		<comments>http://jtgraphic.net/php-function-friday-function/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 00:29:43 +0000</pubDate>
		<dc:creator>jt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Function Friday]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[return]]></category>
		<category><![CDATA[strtotime]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.jtgraphic.net/?p=368</guid>
		<description><![CDATA[<p>Tweet So, I&#8217;ve decided to start including a new post every Friday &#8211; kind of as a discipline thing. I&#8217;m going to write a post on a PHP function every Friday. I&#8217;m not just going to regurgitate the post in &#8230; <a href="http://jtgraphic.net/php-function-friday-function/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/php-function-friday-function/">PHP Function Friday: function</a></p>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fphp-function-friday-function%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/php-function-friday-function/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/php-function-friday-function/"  data-text="PHP Function Friday: function" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/php-function-friday-function/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/php-function-friday-function/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>So, I&#8217;ve decided to start including a new post every Friday &#8211; kind of as a discipline thing.  I&#8217;m going to write a post on a PHP function every Friday.  I&#8217;m not just going to regurgitate the post in the official PHP manual, but I&#8217;m going to list my experience with it along with some creative ways to use it.</p>
<p>With out any further adieu, I&#8217;m posting on the first official building block (which isn&#8217;t technically a function, but I digress) &#8216;function&#8217;:</p>
<h3>PHP Function and Syntax</h3>
<pre>function <em>&lt;function name&gt;</em>(<em>&lt;parameters&gt;</em>) {
   /*add code here*/
}
</pre>
<h3>PHP Manual Entry</h3>
<p>Check here for version information, or anything I may have missed:</p>
<p><a href="http://www.php.net/manual/en/functions.user-defined.php" target="_blank">http://www.php.net/manual/en/functions.user-defined.php</a></p>
<h3>Notes and Use</h3>
<p>This is great for building blocks of code that you repeat a lot.  I like to use it when duplicating XML/HTML code, such as links or form elements, which I will outline below.  Functions, both custom and built in, are the primary building blocks of a good program.  Everything else is just procedural.</p>
<p>Also, on a side note: <a href="http://svn.php.net/viewvc/php/php-src/trunk/CODING_STANDARDS?view=co" target="_blank">PHP Coding Standards</a> is a good read if you&#8217;re really geeky.</p>
<p>An important thing to keep in mind about making custom functions is that someone has probably already made it if it doesn&#8217;t already exist in the built in functions for PHP.  Feel free to jump online and see if someone has already made a function to do what you&#8217;re trying to do.  I like to use the site <a href="http://www.hotscripts.com/" target="_blank">HotScripts.com</a>, which has both free and commercial PHP scripts available.  Chances are: if I need it, they have it.  It saves me a ton of time.</p>
<p>Note in the examples that I precede the function with some explanation of what it does, the author, etc.  This isn&#8217;t needed, but it&#8217;s a REALLY good habit.</p>
<h4>Other Functions Referenced in Examples</h4>
<ul>
<li><a href="http://php.net/manual/en/function.return.php" target="_blank">date()</a></li>
<li><a href="http://php.net/manual/en/function.return.php" target="_blank">strtotime()</a></li>
<li><a href="http://php.net/manual/en/function.return.php" target="_blank">time()</a></li>
<li><a href="http://php.net/manual/en/function.return.php" target="_blank">return()</a></li>
</ul>
<h3>Examples</h3>
<p>Here&#8217;s the meat.  Let&#8217;s make some stuff work.</p>
<h4>Creating Image Links</h4>
<pre>/*
 *  Author: James Thompson, jtGraphic.net
 *
 *  Description
 *  ------------------------------------
 *  This function is for displaying image links in HTML.  It's less typing,
 *  and easier to remember what needs to be slashed out.  An image
 *  with the same name as the file name of the page you're linking to needs to
 *  be placed on the server in the same path as the internal variable
 *  '$image_path' and the same extension as '$image_ext'.
 *
 *  Arguments
 *  ------------------------------------
 *  $url - URL of the link
 *  $extra_tag_html - this is any extra HTML, like class, id, or style
 *
 */

/* Build the function. */

	function create_html_link($name, $extra_tag_html) {
		/* Define internal variables. */
			$image_path = "images/";
			$image_ext   = ".jpg";

		/* Output the HTML. */
			echo
				"&lt;a href="".$name.".php" ".$extra_tag_html."&gt;
					&lt;img src="".$image_path.$name.$image_ext."" /&gt;
				&lt;/a&gt;";
	}

/* Execute the function. */

	create_html_link("home", "class="normal_link"");
	create_html_link("about", "class="normal_link"");
	create_html_link("contact", "class="normal_link"");
</pre>
<h4>Calculate the Number of Days Since Some other Date</h4>
<pre>/*
 *  Author: James Thompson, jtGraphic.net
 *
 *  Description
 *  ------------------------------------
 *  Simple.  This calculates the number of days since X date.
 *
 *  Arguments
 *  ------------------------------------
 *  $date - the date in this format: 'YYYY-MM-DD HH:MM:SS'
 *
 */

/* Build the function. */

	function num_days_since($date) {
		/* Do some time math. */
			$date = strtotime($date);
			$now = time();
			$difference = $now - $date;
			$days = $difference / 86400;

		/* Output the Value. */
			return $days;
	}

/* Execute the function. */

	/* Should return 0 */
		echo num_days_since(date("Y-m-d H:i:s"));
	/* Someone's birthday at 6:02:55AM on Oct 23, 1974 */
		echo num_days_since("1974-10-23 06:02:55");
	/* Since Jan 1, 2009 - no need for time */
		echo num_days_since("2009-01-01");
</pre>
<h3>Examples Elsewhere on this Site:</h3>
<p><a href="http://www.jtgraphic.net/2009/10/tidbit-tuesday-php-holiday-notices-business-sites/" target="_blank">Holiday Notices</a></p>
<h3>Conclusion</h3>
<p>So that&#8217;s the basics.  Functions can be very powerful in reducing the code on your websites.  If you&#8217;d like to see some more <a href="http://www.jtgraphic.net/tag/custom-functions/" target="_blank">custom functions</a>, check out my <a href="http://www.jtgraphic.net/tag/Tidbit-Tuesday/" target="_blank">Tidbit Tuesdays on PHP</a> If you have questions, let me know in the comments.</p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fphp-function-friday-function%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/php-function-friday-function/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/php-function-friday-function/"  data-text="PHP Function Friday: function" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/php-function-friday-function/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/php-function-friday-function/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/php-function-friday-function/">PHP Function Friday: function</a></p>]]></content:encoded>
			<wfw:commentRss>http://jtgraphic.net/php-function-friday-function/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pathfinding in PHP</title>
		<link>http://jtgraphic.net/pathfinding-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pathfinding-php</link>
		<comments>http://jtgraphic.net/pathfinding-php/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 08:35:46 +0000</pubDate>
		<dc:creator>jt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[pathfinding]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.jtgraphic.net/?p=384</guid>
		<description><![CDATA[<p>Tweet I&#8217;ve been playing around with doing some A* pathfinding scripts.  I was looking around on the web and didn&#8217;t find any anywhere, so I decided to make my own rudimentary one.  I&#8217;m going to be expounding on this later.  &#8230; <a href="http://jtgraphic.net/pathfinding-php/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/pathfinding-php/">Pathfinding in PHP</a></p>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fpathfinding-php%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/pathfinding-php/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/pathfinding-php/"  data-text="Pathfinding in PHP" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/pathfinding-php/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/pathfinding-php/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>I&#8217;ve been playing around with doing some A* pathfinding scripts.  I was looking around on the web and didn&#8217;t find any anywhere, so I decided to make my own rudimentary one.  I&#8217;m going to be expounding on this later.  I thought about looking into the A* method and a few others.  Feel free to take the sample below.  <a href="http://www.jtgraphic.net/projects/pathfind.php" target="_blank">Here is a demo too</a>.</p>
<pre>&lt;style&gt;
 * {
 margin: 0px;
 padding: 0px;
 }
&lt;/style&gt;
&lt;body style="margin: 13px 0px 0px 0px; background: #000;"&gt;
&lt;?php
 /* Set the size of our target area */
 $range = 3;

 /* Build the pathfinding function */
 function pathfind($current_square_x, $current_square_y, $map, $steps, $target) {
 /* Give the function a step limit.  We don't want to create an endless loop. */
 $max_steps = 100;

 /* Define the next steps */
 $next_steps[$current_square_y + 1]    [$current_square_x + 1]    = "";
 $next_steps[$current_square_y + 1]    [$current_square_x]     = "";
 $next_steps[$current_square_y + 1]    [$current_square_x - 1]    = "";
 $next_steps[$current_square_y - 1]    [$current_square_x + 1]    = "";
 $next_steps[$current_square_y - 1]    [$current_square_x]        = "";
 $next_steps[$current_square_y - 1]    [$current_square_x - 1]    = "";
 $next_steps[$current_square_y]        [$current_square_x + 1]    = "";
 $next_steps[$current_square_y]        [$current_square_x - 1]    = "";

 /* Do some math to find the distance from here (as the crow flies) to the target) */
 $height = sizeof($map);
 $width = sizeof($map[0]);
 $minimum = sqrt(($width * $width) + ($height * $height));

 /* Find the closest tile */
 foreach($next_steps as $y_key =&gt; $y_value) {
 foreach($y_value as $x_key =&gt; $x_value) {
 if(
 isset($map[$y_key][$x_key]) &amp;&amp;
 $map[$y_key][$x_key] != "closed" &amp;&amp;
 $map[$y_key][$x_key] != "start" &amp;&amp;
 $steps &lt; $max_steps
 ) {
 if($map[$y_key][$x_key] != "traversed") {
 $width  = abs($x_key - $target['x']) + 1;
 $height = abs($y_key - $target['y']) + 1;
 $c = round(sqrt(($width * $width) + ($height * $height)),2);

 if($c &lt; $minimum) {
 $minimum = $c;
 $lowest_distance_position = $x_key."x".$y_key;
 }
 }
 }
 }
 }

 /* Start the next calculation from the closest tile */
 $position = explode("x",$lowest_distance_position);

 if(
 isset($map[$position[1]][$position[0]]) &amp;&amp;
 !($position[0] == $target['x'] &amp;&amp; $position[1] == $target['y'])
 ) {
 $map[$position[1]][$position[0]] = "traversed";

 $path[$position[0]."x".$position[1]] =
 pathfind($position[0], $position[1], $map, $steps + 1, $target);

 if($path) {
 return $path;
 break;
 }
 }

 return array($position[0]."x".$position[1] =&gt; "target");
 break;
 }

 /* Convert the three based array to a step based array. */
 function build_path($path_array, $step_number) {
 if(sizeof($path_array) &gt; 0 &amp;&amp; is_array($path_array)) {
 foreach($path_array as $key =&gt; $value) {
 $this_path[$step_number] = $key;

 if(sizeof($path_array[$key]) &gt; 0) {
 $built_path =
 array_merge(
 $this_path,
 build_path($path_array[$key], $step_number++)
 );
 return $built_path;
 }
 }
 } else {
 return array();
 }
 }

 /* Set the map size. */
 $map_size_x = 43;
 $map_size_y = 22;

 /* Build the blank map. */
 for($y = 0; $y &lt; $map_size_y; $y++) {
 for($x = 0; $x &lt; $map_size_x; $x++) {
 $map[$y][$x] = "open";
 }
 }

 /* Set special sections of the map. */
 $map[15][25] = "closed";
 $map[16][25] = "closed";
 $map[17][25] = "closed";
 $map[18][25] = "closed";
 $map[19][25] = "closed";
 $map[20][25] = "closed";
 $target['x'] = 39;
 $target['y'] = 18;
 $start['x'] = 1;
 $start['y'] = 1;

 $path = pathfind($start['x'], $start['y'], $map, 0, $target);
 $built_path = build_path($path, 1);

 /* Output the final map. */
 echo "&lt;table style="margin: 0px auto;"&gt;";

 foreach($map as $y_key =&gt; $y_value) {
 echo "&lt;tr&gt;";

 foreach($y_value as $x_key =&gt; $x_value) {
 if($x_value == "closed") {
 $background = "F99";
 } elseif ($x_value == "path") {
 $background = "9F9";
 } elseif ($x_key == $start['x'] &amp;&amp; $y_key == $start['y']) {
 $background = "559";
 } elseif (
 $x_key &lt; $target['x'] + $range &amp;&amp;
 $x_key &gt; $target['x'] - $range &amp;&amp;
 $y_key &lt; $target['y'] + $range &amp;&amp;
 $y_key &gt; $target['y'] - $range
 ) {
 $background = "900";
 } elseif(in_array($x_key."x".$y_key,$built_path)) {
 $background = "353";
 } else {
 $background = "333";
 }

 echo
 "&lt;td
 style="
 background: #".$background.";
 width: 20px;
 height: 20px;
 text-align: center;
 "&gt;
 &lt;/td&gt;";
 }

 echo "&lt;/tr&gt;";
 }

 echo "&lt;/table&gt;";
?&gt;
&lt;pre&gt;
 &lt;?php
 //print_r($path);
 ?&gt;
&lt;/pre&gt;
&lt;/body&gt;</pre>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fpathfinding-php%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/pathfinding-php/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/pathfinding-php/"  data-text="Pathfinding in PHP" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/pathfinding-php/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/pathfinding-php/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/pathfinding-php/">Pathfinding in PHP</a></p>]]></content:encoded>
			<wfw:commentRss>http://jtgraphic.net/pathfinding-php/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

