<?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>... coding (the life) &#187; php</title>
	<atom:link href="http://www.marvinmarcelo.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marvinmarcelo.com</link>
	<description>Anything about programming, and a little about me.</description>
	<lastBuildDate>Mon, 09 Jan 2012 13:44:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quickie Visitors Country WP Plugin</title>
		<link>http://www.marvinmarcelo.com/quickie-visitors-country-wp-plugin/</link>
		<comments>http://www.marvinmarcelo.com/quickie-visitors-country-wp-plugin/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 02:14:54 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[me stuff]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[work related]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1382</guid>
		<description><![CDATA[This plugin is dependent on WP/GeoTrack by Johannes Lietz, this is NOT a stand-alone plugin, it won&#8217;t work if WP/GeoTrack is not installed anyway, so it&#8217;s safe. And don&#8217;t look for it in WP Plugins repo, you won&#8217;t find it &#8230; <a href="http://www.marvinmarcelo.com/quickie-visitors-country-wp-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This plugin is dependent on <a title="Visit plugin site" href="http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin">WP/GeoTrack</a> by <a title="Visit author homepage" href="http://dadabase.de/">Johannes Lietz</a>, this is NOT a stand-alone plugin, it won&#8217;t work if <a title="Visit plugin site" href="http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin">WP/GeoTrack</a> is not installed anyway, so it&#8217;s safe.</p>
<p>And don&#8217;t look for it in <a href="http://wordpress.org/extend/plugins/">WP Plugins</a> repo, you won&#8217;t find it there <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
Plugin Name: Top Visitors Flag
Plugin URI: http://www.marvinmarcelo.com/
Description: This plugin displays visitors on sidebar as widget dependent on &lt;a href=&quot;http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin&quot;&gt;WP/GEO-Track plugin&lt;/a&gt;.
Author: Marvin Marcelo
Author URI: http://www.marvinmarcelo.com/
Version: 1.0.0
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> tvf_get_topvisits<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$table_prefix</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select count(*) as `rows` , `country` , `flagname` from `&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$table_prefix</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;geotrack` group by `country` order by `rows` desc limit 0 , 12&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$flagstats</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;li id='top-country-flags'&gt;&lt;h2&gt;Top Visiting Countries&lt;/h2&gt;&lt;div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/*  id string */</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$flagstats</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cf</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$cf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span> <span style="color: #339933;">=</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span> GEOTRACK_URL <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;flags/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cf</span><span style="color: #339933;">-/&gt;</span>flagname <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.png<span style="color: #000099; font-weight: bold;">\&quot;</span> alt=<span style="color: #000099; font-weight: bold;">\&quot;</span>Flag of <span style="color: #006699; font-weight: bold;">$cf-&gt;country</span> with <span style="color: #006699; font-weight: bold;">$cf-&gt;rows</span> visits<span style="color: #000099; font-weight: bold;">\&quot;</span> title=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$cf-&gt;country</span> with <span style="color: #006699; font-weight: bold;">$cf-&gt;rows</span> visits<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: #009900;">&#125;</span>
  <span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> init_tvf_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	register_sidebar_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Top Visitors Flags&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tvf_get_topvisits&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GT_NOT_INSTALLED'</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: #0000ff;">&quot;&lt;!-- You need <span style="color: #000099; font-weight: bold;">\&quot;</span>http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin<span style="color: #000099; font-weight: bold;">\&quot;</span> installed first--&gt;&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>
  add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;plugins_loaded&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;init_tvf_init&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Also, you have to forgive the function, constants, and variables names, we all struggle for a better and sensible one <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/quickie-visitors-country-wp-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP code block &#8211; bringing order to chaos</title>
		<link>http://www.marvinmarcelo.com/php-code-block-bringing-order-to-chaos/</link>
		<comments>http://www.marvinmarcelo.com/php-code-block-bringing-order-to-chaos/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 02:00:48 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[me stuff]]></category>
		<category><![CDATA[work related]]></category>
		<category><![CDATA[basic programming]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[ezsql]]></category>
		<category><![CDATA[grumble]]></category>
		<category><![CDATA[month-year]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1282</guid>
		<description><![CDATA[I had to come up with this post because I&#8217;ve been working on an old CMS about 3 years old (or even more) and I had been wondering why the calendar links cuts off from 2001 to 2003. Task: List &#8230; <a href="http://www.marvinmarcelo.com/php-code-block-bringing-order-to-chaos/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I had to come up with this post because I&#8217;ve been working on an old CMS about 3 years old (or even more) and I had been wondering why the calendar links cuts off from 2001 to 2003.</p>
<p>Task: List a year/month links from the present to the oldest published image sets.</p>
<p>Sounds easy, and I believe it is.</p>
<p>But when I checked on the existing script, this is what I got.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000088;">$month_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'January'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'February'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'March'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;4&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'April'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;5&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'May'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'June'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;7&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'July'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;8&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'August'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;9&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'September'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'October'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;11&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'November'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;12&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'December'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'y2day'</span><span style="color: #339933;">,</span><span style="color: #000088;">$y2day</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$month_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000ff;">'2000'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$m2day</span> <span style="color: #339933;">==</span><span style="color: #000088;">$q</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$week_string</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span>  <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'2007'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>month<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$week_string</span><span style="color: #339933;">;</span>
&nbsp;
		  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$m2day</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tmp_cal_month_now_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">'month'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'string'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'link'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$q</span>
					<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$date_month_now_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$tmp_cal_month_now_array</span><span style="color: #339933;">;</span>	 <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">//for</span>
&nbsp;
	 <span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar_now_month'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date_month_now_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>	<span style="color: #000088;">$c_yeartoday</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//echo $c_yeartoday;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span><span style="color: #000088;">$c_yeartoday</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$q</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//echo $tmp;</span>
&nbsp;
		 <span style="color: #000088;">$tmp_cal_date_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
					  <span style="color: #0000ff;">'year'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$tmp</span>
&nbsp;
				 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #000088;">$date_year_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$tmp_cal_date_array</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">//for</span>
&nbsp;
	<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar_year'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date_year_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$month_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>month<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$q</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$week_string</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$tmp_cal_month_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">'month'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'string'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'link'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$q</span>
					<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$date_month_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$tmp_cal_month_array</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">//for</span>
	 <span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar_month'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date_month_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	 <span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$month_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'2000'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>month<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$week_string</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$tmp_cal_month_old_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">'month'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'string'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'link'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$q</span>
					<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$date_month_old_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$tmp_cal_month_old_array</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">//for</span>
	 <span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar_month_old'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date_month_old_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-1282"></span></p>
<p>Looking at the above script, it looks like they were grouped in to 4 sections, deriving the values of <code>$date_month_now_array</code>, <code>$date_year_array</code>, <code>$date_month_array</code> and <code>$date_month_old_array</code>. And the hardcoded values &#8217;2000&#8242; and &#8217;2007&#8242; will definitely set limit and obviously introduce bug, and so it did. Honestly, I would have coded it this way when I was moving into PHP 3 years ago, and perhaps even now if I&#8217;d have been coding for a whole day confronted with bugs.</p>
<p>Anyway, the main problem with the above code is, there was always a reference for dates and the original programmer didn&#8217;t use it, the date column in the content&#8217;s table. Instead, I&#8217;m guessing, he setup a start &#8216;year&#8217; which is probably he asked someone about the oldest possible year a content was published &#8211; there he arrived at using &#8217;2000&#8242; in the code. And if I&#8217;m not mistaken, this code was written in 2007, LOL, so there was a condition on year set to 2007.</p>
<p>Here&#8217;s how I modified it, optimized it as much (well I hope). The date column had a unix timestamp values, so it&#8217;s not in typical date format.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Calendar modification
 * @author marvin marcelo
 * @uses ez_sql
 * @link http://www.phpclasses.org/browse/package/790.html
 */</span>
<span style="color: #666666; font-style: italic;">/* present */</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$m</span><span style="color: #339933;">,</span> <span style="color: #000088;">$d</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y n j&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select distinct(from_unixtime(updateStartDate, '%Y')) year
          from series_table where updateStartDate &gt; 0 order by updateStartDate desc&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* ezSql stuff */</span>
<span style="color: #000088;">$years</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$years</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$months</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: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #339933;">--</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$endofmonth</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$years</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span>year<span style="color: #0000ff;">&quot;]}-<span style="color: #006699; font-weight: bold;">$j</span>-1&quot;</span><span style="color: #009900;">&#41;</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;">$years</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;year&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* future year-month */</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$years</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;year&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">/* this day in this month of this year is also future, use current date instead */</span>
      <span style="color: #000088;">$endofmonth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$d</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$ts0</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$years</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span>year<span style="color: #0000ff;">&quot;]}-<span style="color: #006699; font-weight: bold;">$j</span>-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* unix timestamp start of month */</span>
    <span style="color: #000088;">$ts1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$years</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span>year<span style="color: #0000ff;">&quot;]}-<span style="color: #006699; font-weight: bold;">$j</span>-<span style="color: #006699; font-weight: bold;">$endofmonth</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* unix timestamp last day or today of month */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from series_table where updateStartDate &gt; <span style="color: #006699; font-weight: bold;">$ts0</span> and updateStartDate &lt; = <span style="color: #006699; font-weight: bold;">$ts1</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$years</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;year&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$month</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$months</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;active&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;j&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;F&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ts0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$months</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;j&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;F&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ts0</span><span style="color: #009900;">&#41;</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: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$months</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$years</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;months&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$months</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/* template */</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$years</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
 * Calendar modification end block
 */</span></pre></div></div>

<p>The process I did &#8230;</p>
<ol>
<li>Select distinct years from all published content by converting unix timestamp to readable year value, then iterate on them</li>
<li>Do a for loop from 12 (december) to 1 (january) to generate a unix timestamp for use in the next query</li>
<li>Query the table for a matching timestamp of the first day and the last day of month-year pair; Use current day of month if iterating year and month matches the present</li>
<li>Show the month link for the year in iteration if a match is found</li>
</ol>
<p>Couple of notes though, I didn&#8217;t name the table as &#8216;series_table&#8217; <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  , it&#8217;s been there years since. I also named my variables when referring to start and end as <code>$x0</code> and <code>$x1</code>, <code>$ts0</code> and <code>$ts1</code>. I got used to this when college years in physics &#8211; the start and end of a distance, I don&#8217;t know, I just like the thought <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  .</p>
<p>Hope it didn&#8217;t went order to chaos at all!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/php-code-block-bringing-order-to-chaos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Variable, variables and lots of variables</title>
		<link>http://www.marvinmarcelo.com/variable-variables-and-lots-of-variables/</link>
		<comments>http://www.marvinmarcelo.com/variable-variables-and-lots-of-variables/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 03:17:34 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[me stuff]]></category>
		<category><![CDATA[work related]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1232</guid>
		<description><![CDATA[List of variable names, oddly named and other stuff I&#8217;m glad I bumped into . Found them in project about 5 or 6 yrs old that needs modification and I believe optimization too, yes really. So why glad? Because I &#8230; <a href="http://www.marvinmarcelo.com/variable-variables-and-lots-of-variables/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>List of variable names, oddly named and other stuff I&#8217;m glad I bumped into <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  . Found them in project about 5 or 6 yrs old that needs modification and I believe optimization too, yes really. So why glad? Because I realized the way I named my variables isn&#8217;t that bad at all.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * This one is on top of a movie player page. Maybe 'he' wasn't so sure 
 * that the parameters passed on to this page is for a 'video'. Just making
 * sure for the nth time I guess.
 */</span>
<span style="color: #000088;">$videoistrue</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
 * I think 'he' hate lines. And this one is good, page title is saved 
 * in a session variable, so if another programmer writes a new page
 * and forgot to assign $_SESSION['pagetitle'] a new value for an FAQ
 * page, say faq.php, it'd show up &lt;title&gt;Show Series&lt;/title&gt;
 */</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pagetitle'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Show Series&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
 * ... and it went on and on
 * $_SESSION['pagetitle'] = &quot;Calendar&quot;;
 * session_start();$_SESSION['pagetitle'] = &quot;Browse Model&quot;;
 *
 * Hmmmm, $ii as iteration variable, struggling with names? I often 
 * use $i, $n or $x, sometime $c, hehehe! I've seen $i for many. And 
 * have you noticed the class name 'smalleditnoline', can it be any 
 * longer? Yes! and if he had enough time, it may have look like 
 * 'smalleditnolinewitharialbold' or 'smalleditnolineFFFbgcolor333fgcolor'
 * crazy! This is CSS anyway, will surely post one for that, hahaha!
 */</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ii</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #000088;">$ii</span><span style="color: #339933;">&lt;</span> <span style="color: #339933;">=</span><span style="color: #000088;">$totalpages</span><span style="color: #339933;">;</span><span style="color: #000088;">$ii</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ii</span><span style="color: #339933;">==</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;font class='smallediton'&gt;[<span style="color: #006699; font-weight: bold;">$ii</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;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='?sort=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;page=<span style="color: #006699; font-weight: bold;">$ii</span>' class='smalleditnoline'&gt;[<span style="color: #006699; font-weight: bold;">$ii</span>]&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009933; font-style: italic;">/**
 * more variables with default values, note that this is set just
 * before a loop starts
 */</span>
<span style="color: #000088;">$thisCat</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$firstrun</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$firstrow</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rowcount</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
 * &quot;NO QUOTES&quot; for key names in square brackets :( 
 * if only my IDE could complain
 */</span>
<span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span>catadded<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span>keywordadded<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span>modeladded<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
 * Consistent! Maybe 'He' doesn't want anybody to easily understand 
 * the script that's why no new lines after semi-colon at least.
 */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$seriesRow</span><span style="color: #009900;">&#91;</span>seriesNo<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$seriesNoTxt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$seriesRow</span><span style="color: #009900;">&#91;</span>seriesNo<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #000088;">$seriesNoTxt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$seriesRow</span><span style="color: #009900;">&#91;</span>seriesNo<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

</pre>
<p>Ok, enough of grumbling here. I have released my frustration for today, going back to work. But if I am to start a project or even a simple script, I follow formatting conventions, consistent quotes and escapes, logical variable names and useful comments with links and samples. It doesn't only make your code readable, it helps a lot for the next programmer to just add-in the stuff he needs to and keeping his sanity.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/variable-variables-and-lots-of-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Breaking the silence</title>
		<link>http://www.marvinmarcelo.com/breaking-the-silence/</link>
		<comments>http://www.marvinmarcelo.com/breaking-the-silence/#comments</comments>
		<pubDate>Mon, 11 May 2009 02:27:24 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[me stuff]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/breaking-the-silence/</guid>
		<description><![CDATA[So, I haven&#8217;t really got time posting stuff here. Its because I&#8217;ve been trying to finish my new site after my day job. It is called swerteka.com, and I&#8217;m gonna give it as free ad posting service. But it&#8217;s still &#8230; <a href="http://www.marvinmarcelo.com/breaking-the-silence/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So, I haven&#8217;t really got time posting stuff here. Its because I&#8217;ve been trying to finish my new site after my day job. It is called swerteka.com, and I&#8217;m gonna give it as free ad posting service.</p>
<p>But it&#8217;s still a long way to go, and it will be loaded by the CMS script I&#8217;ve been working on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/breaking-the-silence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back to work</title>
		<link>http://www.marvinmarcelo.com/back-to-work/</link>
		<comments>http://www.marvinmarcelo.com/back-to-work/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 12:26:19 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[work related]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[ning]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[poweron]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=27</guid>
		<description><![CDATA[Over the next few days, I&#8217;ll be a &#8220;ning&#8221; developer , actually I started playing around the code about a month ago. But taken away off some other projects (feature integration) on PhpFox. And as always, I started from the &#8230; <a href="http://www.marvinmarcelo.com/back-to-work/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Over the next few days, I&#8217;ll be a <strong>&ldquo;ning&rdquo;</strong> developer <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  , actually I started playing around the code about a month ago. But taken away off some other projects (feature integration) on <abbr title="phpFoX Social Networking Script">PhpFox</abbr>.</p>
<p>And as always, I started from the index.php going thru all the include files.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</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: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'NF_APP_BASE'</span><span style="color: #339933;">,</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> NF_APP_BASE <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/lib/index.php'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Then look for anything that says &ldquo;request&rdquo; which is basically the point of interaction, how it receives it and handles it. After that, I look for the database object, its methods. Until the haunt kept on going.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/back-to-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

