<?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>DJS Consulting Tech Blog &#187; PHP</title>
	<atom:link href="http://techblog.djs-consulting.com/category/programming/php/feed" rel="self" type="application/rss+xml" />
	<link>http://techblog.djs-consulting.com</link>
	<description>Technical Information You Can Use</description>
	<lastBuildDate>Mon, 02 Jan 2012 18:44:33 +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>Tech Blog 3.0 (aka &#8220;You win, PHP&#8230;&#8221;)</title>
		<link>http://techblog.djs-consulting.com/2011/tech-blog-3-0.html</link>
		<comments>http://techblog.djs-consulting.com/2011/tech-blog-3-0.html#comments</comments>
		<pubDate>Thu, 25 Aug 2011 04:12:44 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[General Info]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[blogengine]]></category>
		<category><![CDATA[mpm]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pre-fork]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[worker]]></category>

		<guid isPermaLink="false">http://techblog.djs-consulting.com/?p=249</guid>
		<description><![CDATA[After a little over a year running on Tech Blog 2.0, you are now viewing version 3.0.  For this version, we&#8217;ve returned to WordPress from BlogEngine.  There are several issues that colluded to drive this change, most of which surrounded &#8230; <a href="http://techblog.djs-consulting.com/2011/tech-blog-3-0.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After a little over a year running on <a title="Tech Blog 2.0 • DJS Consulting Tech Blog" href="http://techblog.djs-consulting.com/2010/tech-blog-2-0.html">Tech Blog 2.0</a>, you are now viewing version 3.0.  For this version, we&#8217;ve returned to <a title="WordPress" href="http://wordpress.org">WordPress</a> from <a title="BlogEngine.NET" href="http://dotnetblogengine.net">BlogEngine</a>.  There are several issues that colluded to drive this change, most of which surrounded PHP and its crazy behavior.  (Geeky details follow &#8211; skip to the paragraph starting with &#8220;Bottom line:&#8221; if you don&#8217;t want the geek stuff.  I bolded it so it would be easy to spot.)</p>
<p>PHP&#8217;s recommended configuration is to run under Apache using the pre-fork multi-processing module (MPM).  The advantage to this is that Apache does not have to spin off another process to handle each request; it handles it in the same thread.  However, this means that each instance of the server must have all enabled modules loaded.  This means that each instance of the server (AKA &#8220;thread&#8221;) is very large, so the number of threads run is lower (typically 5-15 in a server the size we&#8217;re on).  Also, this means that each thread can only handle one request at a time; if you have 7 threads configured, each serving one of 7 requests, and an 8th request comes it, it has to wait for one to finish.  If the requests are served quickly, this may not be a problem; however, the avalanche of request that follow the typical front-page mention on mega-blogs can easily overwhelm it.</p>
<p>To fix this problem, there is another MPM, this one called worker.  In this scenario, there are spare thread waiting to fill requests, and these can spawn other threads to do further work if required.  So, the Apache threads would realize that a request needs to be handled by PHP, and pass it off to that process to be completed.  The Apache memory footprint is much smaller; it serves the images, scripts, and other static files, and passes off the requests that require heavy lifting.  PHP, then, has a (FastCGI) process where it receives these requests, processes them, and returns the response to the caller.  Because each of these threads only has to load the PHP requirements, they are smaller too, so you can have more threads processing at the same time; you just might survive that front-page mention!  (This is the same technique applied by LightTPD and Nginx, two other servers I tried at various times.)</p>
<p>It is in this scenario where PHP fails to live up to its expectations.  These PHP processes would simply stop responding, but the controller thinks they&#8217;re still there.  The end result to the user is a site that just sits and waits for output that will never come.  Eventually, they may receive a Gateway Timeout or Bad Gateway error.  The problem is worse on slower sites, but even popular sites seemed to fall victim to this from time to time.  This was also a problem whether PHP controlled its threads, or Apache controlled them.</p>
<p>The one thing that really perturbs me is instability.  If something is broken, I can fix it; if it works, I can fix it &#8217;til it&#8217;s broke.  :)  But something that works sometimes, and other times doesn&#8217;t, simply won&#8217;t fly.  I was able to introduce some stability by restarting the server 4 times a day, but that&#8217;s a band-aid, not a long term solution.  I was tired of fighting.</p>
<p><strong>Bottom line</strong>: the configuration required for a stable server is in opposition to a lean-and-mean configuration.  So, I installed the required Apache modules, and will continue to run my PHP-serving server at a configuration twice as large as it needs to be.  I&#8217;ll eventually move the Mono (.NET) processes to another machine, where the fast configuration won&#8217;t stability problems.</p>
<p>But, PHP isn&#8217;t all.  While I would still heartily recommend BlogEngine.NET to someone who was going to serve the blog from a Windows machine, but I had some issues getting upgrades to go smoothly under Mono.  It also is optimized for fast serving, at the expense of RAM.  At this point, that&#8217;s not the tradeoff we need.</p>
<p>Finally, with this update, the blog has received its first new theme.  It&#8217;s a clean, clear theme that should serve the content well.  Plus, the social media icons up in the corner are just too cool, IMO.  I&#8217;ve also applied tags to all posts except the &#8220;My Linux Adventure&#8221; series, and this theme displays them.  (Comments are not here now, but will be migrated shortly.)</p>
<p>So, there you have it.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.djs-consulting.com/2011/tech-blog-3-0.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Handy PHP Backup Script</title>
		<link>http://techblog.djs-consulting.com/2008/a-handy-php-backup-script.html</link>
		<comments>http://techblog.djs-consulting.com/2008/a-handy-php-backup-script.html#comments</comments>
		<pubDate>Sat, 29 Mar 2008 05:06:37 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://techblog.johnson/?p=152</guid>
		<description><![CDATA[I found a script over on the Lunarpages Forums about using PHP to back up your site. I have taken it, modified it a little, beefed up the documentation a lot, and am now posting it here. You can download &#8230; <a href="http://techblog.djs-consulting.com/2008/a-handy-php-backup-script.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I found a script over on the Lunarpages Forums about <a href="http://www.lunarforums.com/lunarpages_how_tos/site_and_mysql_backups_via_cron-t22118.0.html" title="Site and MySQL backups via cron - Lunarforums">using PHP to back up your site</a>.  I have taken it, modified it a little, beefed up the documentation a lot, and am now posting it here.  You can <a href="http://djs-consulting.com/linux/generic_backup.txt" title="Generic Backup Script">download the source code</a> for it, and it is also displayed below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
</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: #009933; font-style: italic;">/**
 * Generic Backup Script.
 * 
 * To configure this script for your purposes, just edit the parameters below.
 * Once you have the parameters set properly, when the script executes, it will
 * create an archive file, gzip it, and e-mail it to the address specified.  It
 * can be executed through cron with the command
 * 
 * php -q [name of script]
 * 
 * You are free to use this, modify it, copy it, etc.  However, neither DJS
 * Consulting nor Daniel J. Summers assume any responsibility for good or bad
 * things that happen when modifications of this script are run.
 * 
 * @author Daniel J. Summers &amp;lt;daniel@djs-consulting.com&amp;gt;
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// --- SCRIPT PARAMETERS ---</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- File Name --
	This is the name of the file that you're backing up, and should contain no
	slashes.  For example, if you're backing up a database, this might look
	something like...
$sFilename = &quot;backup-my_database_name-&quot; . date(&quot;Y-m-d&quot;) . &quot;.sql&quot;; */</span>
<span style="color: #000088;">$sFilename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;backup-[whatever-it-is]-&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-m-d&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.[extension]&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- E-mail Address --
	This is the e-mail address to which the message will be sent. */</span>
<span style="color: #000088;">$sEmailAddress</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;[your e-mail address]&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- E-mail Subject --
	This is the subject that will be on the e-mail you receive. */</span>
<span style="color: #000088;">$sEmailSubject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;[something meaningful]&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- E-mail Message --
	This is the text of the message that will be sent. */</span>
<span style="color: #000088;">$sMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Compressed database backup file <span style="color: #006699; font-weight: bold;">$sFilename</span>.gz attached.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- Backup Command --
	This is the command that does the work.
&nbsp;
	A note on the database commands - your setup likely requires a password
	for these commands, and they each allow you to pass a password on the
	command line.  However, this is very insecure, as anyone who runs &quot;ps&quot; can
	see your password!  For MySQL, you can create a ~/.my.cnf file - it is
	detailed at http://dev.mysql.com/doc/refman/4.1/en/password-security.html .
	For PostgreSQL, the file is ~/.pgpass, and it is detailed at
	http://www.postgresql.org/docs/8.0/interactive/libpq-pgpass.html .  Both of
	these files should be chmod-ded to 600, so that they can only be viewed by
	you, the creator.
&nbsp;
	That being said, some common commands are...
&nbsp;
- Backing Up a MySQL Database
$sBackupCommand = &quot;mysqldump -u [user_name] [db_name] &amp;gt; $sFilename&quot;;
&nbsp;
- Backing Up a PostgreSQL Database
$sBackupCommand = &quot;pg_dump [db_name] -h localhost -U [user_name] -d -O &amp;gt; $sFilename&quot;;
&nbsp;
- Backing Up a set of files (tar and gzip)
$sBackupCommand = &quot;tar cvf $sFilename [directory]/*&quot;;
&nbsp;
Whatever command you use, this script appends .gz to the filename after the command is executed.  */</span>
<span style="color: #000088;">$sBackupCommand</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;[a backup command]&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// --- END OF SCRIPT PARAMETERS ---</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// Edit below at your own risk.  :)</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Do the backup.</span>
<span style="color: #000088;">$sResult</span> <span style="color: #339933;">=</span> <span style="color: #990000;">passthru</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sBackupCommand</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;; gzip <span style="color: #006699; font-weight: bold;">$sFilename</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sFilename</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.gz&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create the message.</span>
<span style="color: #000088;">$sMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Compressed database backup file <span style="color: #006699; font-weight: bold;">$sFilename</span> attached.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sMimeBoundary</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&amp;lt;&amp;lt;&amp;lt;:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chunk_split</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sFilename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sHeaders</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: <span style="color: #006699; font-weight: bold;">$sEmailAddress</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-type: multipart/mixed;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; boundary=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$sMimeBoundary</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sContent</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;This is a multi-part message in MIME format.<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;--<span style="color: #006699; font-weight: bold;">$sMimeBoundary</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Type: text/plain; charset=<span style="color: #000099; font-weight: bold;">\&quot;</span>iso-8859-1<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Transfer-Encoding: 7bit<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #000088;">$sMessage</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;--<span style="color: #006699; font-weight: bold;">$sMimeBoundary</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Disposition: attachment;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Type: Application/Octet-Stream; name=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$sFilename</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Transfer-Encoding: base64<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #000088;">$sData</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;--<span style="color: #006699; font-weight: bold;">$sMimeBoundary</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Send the message.</span>
<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sEmailAddress</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sEmailSubject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sContent</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sHeaders</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Delete the file - we don't need it any more.</span>
<span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sFilename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://techblog.djs-consulting.com/2008/a-handy-php-backup-script.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Algorithm for One-to-Many Child Table Updates</title>
		<link>http://techblog.djs-consulting.com/2008/algorithm-for-one-to-many-child-table-updates.html</link>
		<comments>http://techblog.djs-consulting.com/2008/algorithm-for-one-to-many-child-table-updates.html#comments</comments>
		<pubDate>Sat, 29 Mar 2008 02:13:24 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[nsx]]></category>
		<category><![CDATA[one-to-many]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://techblog.johnson/?p=150</guid>
		<description><![CDATA[While working on the Not So Extreme Makeover: Community Edition site, I came up with an algorithm that simplifies anything else I&#8217;ve ever written to deal with this condition. I&#8217;ll set the scenario, explain the algorithm, share how I implemented &#8230; <a href="http://techblog.djs-consulting.com/2008/algorithm-for-one-to-many-child-table-updates.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While working on the <a href="http://notsoextreme.org" title="Not So Extreme Makeover: Community Edition">Not So Extreme Makeover: Community Edition</a> site, I came up with an algorithm that simplifies anything else I&#8217;ve ever written to deal with this condition.  I&#8217;ll set the scenario, explain the algorithm, share how I implemented it in PHP, and provide a modification if the scenario is a bit more complicated.</p>
<p><strong>Scenario</strong> &#8211; You have two parent tables, and a child table with a many-to-one relationship with both parent tables, used to map entries in the two parent tables to each other.  For this example, we&#8217;ll use these three tables&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> volunteer <span style="color: #66cc66;">&#40;</span>
    vol_id  <span style="color: #993333; font-weight: bold;">INTEGER</span>  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    vol_last_name  <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    <span style="color: #66cc66;">...</span>etc<span style="color: #66cc66;">...</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>vol_id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> r_volunteer_area <span style="color: #66cc66;">&#40;</span>
    rva_id  <span style="color: #993333; font-weight: bold;">INTEGER</span>  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    rva_description  <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>rva_id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> volunteer_area <span style="color: #66cc66;">&#40;</span>
    va_volunteer_id  <span style="color: #993333; font-weight: bold;">INTEGER</span>  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    va_area_id  <span style="color: #993333; font-weight: bold;">INTEGER</span>  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>va_volunteer_id<span style="color: #66cc66;">,</span> va_area_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>va_volunteer_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> volunteer <span style="color: #66cc66;">&#40;</span>vol_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>va_area_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> r_volunteer_area <span style="color: #66cc66;">&#40;</span>rva_id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p><strong>Algorithm</strong> &#8211; The three-step algorithm is as follows&#8230;</p>
<ol>
<li>Create a comma-delimited string of IDs for the child table.</li>
<li>Delete the IDs from the child table that are not in the list.</li>
<li>Insert the IDs into the child table that are not there already.</li>
</ol>
<p><strong>Implementation</strong> &#8211; In PHP, if you have an array, it&#8217;s easy to come up with comma-delimited list.  To get an array of values back in a post, define your fields with &#8220;[]&#8221; after the name&#8230;</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: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;area[]&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;chkArea1&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;chkArea1&quot;</span><span style="color: #339933;">&gt;</span>Do Something<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;area[]&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;chkArea7&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;7&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;chkArea7&quot;</span><span style="color: #339933;">&gt;</span>Do Something Else<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Here&#8217;s the PHP code, using <a href="http://us.php.net/pdo" title="PHP Data Objects (PDO)">PHP Data Objects (PDO)</a> as the database interface, behind a helper class that creates the statement, appends the parameters, and executes it.  <em>(The &#8220;quoting&#8221; escapes the statement to avoid potential SQL injection attacks &#8211; putting it in its own class would make the implementation here much cleaner.)</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * STEP 1
 *    Create a comma-delimited list of IDs.
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Quote will return the string as '2,3,4' - since we're using this</span>
<span style="color: #666666; font-style: italic;">// as an IN clause of integers, we'll strip the quotes off.</span>
<span style="color: #000088;">$sAreas</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">quote</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;area&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sAreas</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sAreas</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sAreas</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Quote the volunteer ID.</span>
<span style="color: #000088;">$iVol</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">quote</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;vol&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_INT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * STEP 2
 *    Delete the IDs that are no longer in the list.
 */</span>
<span style="color: #000088;">$dbService</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">executeCommand</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;DELETE FROM volunteer_area
    WHERE   va_volunteer_id = ?
        AND va_area_id NOT IN (<span style="color: #006699; font-weight: bold;">$sAreas</span>)&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iVol</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * STEP 3
 *    Insert the IDs that are not yet in the list.
 */</span>
<span style="color: #000088;">$dbService</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">executeCommand</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;INSERT INTO volunteer_area
        SELECT <span style="color: #006699; font-weight: bold;">$iVol</span>, rva_id
        FROM r_volunteer_area
        WHERE   rva_id IN (<span style="color: #006699; font-weight: bold;">$sAreas</span>)
            AND rva_id NOT IN
            (SELECT va_area_id
&nbsp;
            FROM volunteer_area
            WHERE va_volunteer_id = ?)&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iVol</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Modification</strong> &#8211; Suppose that now you accepted comments along with each of the checkboxes, so a simple two-integer insert/delete is no longer sufficient.  You would still only need to break step 3 into two steps.</p>
<ol>
<li>Get a list of IDs to update.</li>
<li>For each ID in the posted list
<ol>
<li>If the ID exists in the update list, update it.</li>
<li>Otherwise, insert it.</li>
</ol>
</li>
</ol>
<p>The implementation would then be able to use this list to make the decision without hitting the database every time.</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Assume this returns an associative array of IDs.</span>
<span style="color: #000088;">$aUpdates</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbService</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">performSelect</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;SELECT va_area_id
    FROM volunteer_area
    WHERE   va_volunteer_id = ?
        AND va_area_id IN (<span style="color: #006699; font-weight: bold;">$sAreas</span>)&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iVol</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;area&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$iArea</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: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iArea</span><span style="color: #339933;">,</span> <span style="color: #000088;">$aUpdates</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Update the table</span>
        <span style="color: #339933;">...</span>etc<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: #666666; font-style: italic;">// Insert into the table</span>
        <span style="color: #339933;">...</span>etc<span style="color: #339933;">...</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I think you&#8217;ll agree that this is much better than spinning through a loop, doing a count on each ID to see if it exists, then either doing an update or an insert based on the count.  And, while the implementation here is PHP, it could easily be implemented in any language that supports arrays and database access.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.djs-consulting.com/2008/algorithm-for-one-to-many-child-table-updates.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Incorporating an Akismet Counter Into a WordPress Theme</title>
		<link>http://techblog.djs-consulting.com/2007/incorporating-an-akismet-counter-into-a-wordpress-theme.html</link>
		<comments>http://techblog.djs-consulting.com/2007/incorporating-an-akismet-counter-into-a-wordpress-theme.html#comments</comments>
		<pubDate>Mon, 06 Aug 2007 16:14:00 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[aksimet]]></category>
		<category><![CDATA[counter]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://techblog.johnson/?p=107</guid>
		<description><![CDATA[Akismet is, by far, the most popular anti-spam plug-in for WordPress. (It comes bundled with the download, so that gets it market share. But, it&#8217;s also very, very good.) It comes with a counter that can be put into a &#8230; <a href="http://techblog.djs-consulting.com/2007/incorporating-an-akismet-counter-into-a-wordpress-theme.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a title="Akismet" href="http://akismet.com">Akismet</a> is, by far, the most popular anti-spam plug-in for WordPress. (It comes bundled with the download, so that gets it market share. But, it&#8217;s also very, very good.) It comes with a counter that can be put into a WordPress theme. It&#8217;s attractive, but its light blue color may not integrate well into a given theme.</p>
<p>I went digging around in the source code, and found the line that actually pulls the count from the database. Using this parameter, I was able to integrate a spam count into the sidebar that has a look consistent with the rest of the site.</p>
<p>Here&#8217;s the code that&#8217;s in use on the theme on this site.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;li id=&quot;spamstats&quot;&gt;
	&lt;h2&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Akismet-Eaten Spam:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h2&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;http://akismet.com&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
			<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;akismet_spam_count&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			and counting...&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/li&gt;</pre></td></tr></table></div>

<p>Of course, line 5 is the important one &#8211; that&#8217;s how to get the number, formatted for whatever locale the server is set up for. (On my <a title="Daniel J. Summers" href="http://daniel.summershome.org">personal blog</a>, the number is up over 1,400!)</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.djs-consulting.com/2007/incorporating-an-akismet-counter-into-a-wordpress-theme.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Posting Source Code in WordPress, Take 2</title>
		<link>http://techblog.djs-consulting.com/2007/posting-source-code-in-wordpress-take-2.html</link>
		<comments>http://techblog.djs-consulting.com/2007/posting-source-code-in-wordpress-take-2.html#comments</comments>
		<pubDate>Wed, 13 Jun 2007 17:33:15 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[geshi]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wp-syntax]]></category>

		<guid isPermaLink="false">http://techblog.johnson/?p=88</guid>
		<description><![CDATA[In my searching, I have found another WordPress source code plugin, called wp-syntax. This one uses GeSHi, the Generic Syntax Highlighter. It features many languages, and is extensible to even more. (If I ever post a COBOL snippet, I&#8217;ll probably &#8230; <a href="http://techblog.djs-consulting.com/2007/posting-source-code-in-wordpress-take-2.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In my searching, I have found another WordPress source code plugin, called <a title="WP Syntax Plugin" href="http://wordpress.org/extend/plugins/wp-syntax/">wp-syntax</a>. This one uses <a title="GeSHi" href="http://qbnz.com/highlighter/">GeSHi</a>, the Generic Syntax Highlighter. It features many languages, and is extensible to even more. (If I ever post a COBOL snippet, I&#8217;ll probably add COBOL support to it, and contribute it to the codebase.)</p>
<p>To use it, you simply put a pre tag, followed by &#8220;lang=[language]&#8220;. It will also do line numbering. Of course, with a single &#8220;language&#8221; parameter, the embedded language will not be highlighted as well. In this case, the previous plug-in works better; although the syntax highlighting has to be done manually, it can handle multiple languages.</p>
<p>Here is what the example from the &#8220;Category DropDowns in WordPress&#8221; post looks like with <strong>lang=&#8221;php&#8221;</strong>…</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</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: #009933; font-style: italic;">/**
 * This creates a list of category links that can be used with a category dropdown
 */</span>
<span style="color: #000088;">$aCategories</span> <span style="color: #339933;">=</span> get_all_category_ids<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$iMaxCat</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$aCategories</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$iThisCat</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;">$iMaxCat</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$iThisCat</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$iMaxCat</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$iThisCat</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$iMaxCat</span><span style="color: #339933;">++;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;div style=&quot;text-align:center;&quot;&gt;
    &lt;form name=&quot;categoryform&quot; action=&quot;&quot; style=&quot;text-align:center;&quot;&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        var aLink = new Array(<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iMaxCat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>);
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$aCategories</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$iThisCat</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;aLink[<span style="color: #006699; font-weight: bold;">$iThisCat</span>] = <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">.</span> get_category_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$iThisCat</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
        function goCat() {
            window.location =
                aLink[document.getElementById('cat')[document.getElementById('cat').selectedIndex].text;
        }
    &lt;/script&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_dropdown_categories<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class=sidebardropdown&amp;orderby=name&amp;show_count=1&amp;hierarchical=1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;br /&gt;
    &lt;button class=&quot;sidebarbutton&quot; type=&quot;button&quot; style=&quot;margin-top:5px;&quot; onclick=&quot;goCat();&quot;&gt;View Category&lt;/button&gt;
    &lt;/form&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>And, here&#8217;s what it looks like with <strong>lang=&#8221;javascript&#8221;</strong>…</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;?php
/**
 * This creates a list of category links that can be used with a category dropdown
 */
$aCategories = get_all_category_ids();
$iMaxCat = 0;
foreach($aCategories as $iThisCat) {
    if ($iMaxCat &lt; $iThisCat) {
        $iMaxCat = $iThisCat;
    }
}
$iMaxCat++;
?&gt;&lt;div style=&quot;text-align:center;&quot;&gt;
    &lt;form name=&quot;categoryform&quot; action=&quot;&quot; style=&quot;text-align:center;&quot;&gt;
    <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #003366; font-weight: bold;">var</span> aLink <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;?</span>php echo<span style="color: #009900;">&#40;</span>$iMaxCat<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">?&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;?</span>php
foreach<span style="color: #009900;">&#40;</span>$aCategories <span style="color: #000066; font-weight: bold;">as</span> $iThisCat<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    echo<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;aLink[$iThisCat] = <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> . <span style="color: #660066;">get_category_link</span><span style="color: #009900;">&#40;</span>$iThisCat<span style="color: #009900;">&#41;</span> . <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #339933;">?&gt;</span>
        <span style="color: #003366; font-weight: bold;">function</span> goCat<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            window.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span>
                aLink<span style="color: #009900;">&#91;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'cat'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'cat'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">selectedIndex</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">text</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
    &lt;?php wp_dropdown_categories('class=sidebardropdown&amp;orderby=name&amp;show_count=1&amp;hierarchical=1'); ?&gt;
    &lt;br /&gt;
    &lt;button class=&quot;sidebarbutton&quot; type=&quot;button&quot; style=&quot;margin-top:5px;&quot; onclick=&quot;goCat();&quot;&gt;View Category&lt;/button&gt;
    &lt;/form&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>This is another option, and is probably what I&#8217;ll use for single-language posts, or posts where the embedded language may not be crucial.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.djs-consulting.com/2007/posting-source-code-in-wordpress-take-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Category Drop-Down in WordPress</title>
		<link>http://techblog.djs-consulting.com/2007/category-drop-down-in-wordpress.html</link>
		<comments>http://techblog.djs-consulting.com/2007/category-drop-down-in-wordpress.html#comments</comments>
		<pubDate>Thu, 24 May 2007 15:00:15 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[dropdown]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://techblog.johnson/?p=83</guid>
		<description><![CDATA[WordPress provides a template tag, wp_dropdown_categories, that inserts a drop-down list (the HTML &#60;select&#62; element) of categories, where the value of each item is the ID from the database. This works fine if you are not using rewrite rules (AKA &#8230; <a href="http://techblog.djs-consulting.com/2007/category-drop-down-in-wordpress.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a title="WordPress" href="http://wordpress.org">WordPress</a> provides a <a title="Template Tags - WordPress Codex" href="http://codex.wordpress.org/Template_Tags">template tag</a>, <a title="wp_dropdown_categories - WordPress Codex" href="http://codex.wordpress.org/Template_Tags/wp_dropdown_categories">wp_dropdown_categories</a>, that inserts a drop-down list (the HTML &lt;select&gt; element) of categories, where the value of each item is the ID from the database. This works fine if you are not using rewrite rules (AKA &#8220;pretty links&#8221;) &#8211; you can construct a URL using the value (?cat=[number]). However, if you use any sort of rewrite rules, this does not work. I recently converted my <a title="Daniel J. Summers" href="http://daniel.summershome.org">personal site</a>, which uses the Pool theme, to utilize a JavaScript array to assist with displaying category pages.</p>
<p>Here&#8217;s the code&#8230;</p>
<p><em>Edit: Code has been moved to <a title="Posting Source Code in WordPress, Take 2 • DJS Consulting Tech Blog" href="/2007/posting-source-code-in-wordpress-take-2.html">this post</a>.</em></p>
<p>This works for both &#8220;pretty&#8221; and standard links, as it uses the template tag <a title="get_category_link - WordPress Codex" href="http://codex.wordpress.org/Function_Reference/get_category_link">get_category_link</a> to specify the link.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.djs-consulting.com/2007/category-drop-down-in-wordpress.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wow</title>
		<link>http://techblog.djs-consulting.com/2004/wow.html</link>
		<comments>http://techblog.djs-consulting.com/2004/wow.html#comments</comments>
		<pubDate>Sun, 01 Aug 2004 06:00:34 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[Internet Apps]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Red Hat / Fedora]]></category>

		<guid isPermaLink="false">http://techblog.johnson/?p=46</guid>
		<description><![CDATA[Today I installed Fedora Core 2. This thing is slick! WBEL looked a lot like RH8, which I had seen before my renewed Linux learning began. FC2 has a graphical loader that hides a lot of the background stuff (unless &#8230; <a href="http://techblog.djs-consulting.com/2004/wow.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I installed Fedora Core 2. This thing is slick! WBEL looked a lot like RH8, which I had seen before my renewed Linux learning began. FC2 has a graphical loader that hides a lot of the background stuff (unless an error occurs) &#8211; that&#8217;s cool. During the install, I skipped OpenOffice.org and MySQL, although I installed PHP with MySQL support. The reason for that is that I wanted to get the latest and greatest versions of those two products. We&#8217;ll see if this proves to be a good decision or not.</p>
<p>The wireless network card still wasn&#8217;t recognized (phooey). I did some more searching, armed with the knowledge that I have an adm8211 chipset. One of the first hits under Google&#8217;s Linux search for &#8220;adm8211&#8243; pointed me to a project called <a href="http://ndiswrapper.sourceforge.net/">NDISwrapper</a>. This is a &#8220;wrapper&#8221; that uses the vendor&#8217;s Windows DLL file, and converts the hooks from Windows to Linux. Doing this, this driver can (in theory) support most any network card, especially those that aren&#8217;t in the Linux Hardware Compatibility List (HCL). I downloaded it, compiled it, and followed the directions to install my driver under it. I still wasn&#8217;t able to create a connection, but on a hunch, I restarted the computer. NDISwrapper is also a kernel module, and I know that often those are only read at startup. Once the computer was restarted, I was able to create a connection, and now my network card works! YEA!!! (And it was only one night&#8217;s worth of work &#8211; much better.)</p>
<p>Now that I have networking working under both operating systems, I plan to try to get four things working the same, whether I&#8217;m booted to WXP or Linux &#8211; E-mail (using Mozilla Thunderbird), PHP (using Apache on Linux, IIS on WXP), MySQL (using the exact same version on both), and a web server that uses the same html root directory (again, Apache on Linux, IIS on WXP). If I didn&#8217;t already have IIS up, running, and configured under WXP, I&#8217;d probably just do Apache on both, but this will be interesting &#8211; it should work, as I don&#8217;t have many creative permission rules.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.djs-consulting.com/2004/wow.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

