<?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>Christoffer Kjølbæk &#187; PHP</title>
	<atom:link href="http://ostehamster.dk/blog/index.php/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://ostehamster.dk/blog</link>
	<description>I have a blog, therefore I am…</description>
	<lastBuildDate>Sun, 18 Jul 2010 12:16:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9-rare</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP function to get current SVN ID</title>
		<link>http://ostehamster.dk/blog/index.php/2010/07/18/php-function-to-get-current-svn-id/</link>
		<comments>http://ostehamster.dk/blog/index.php/2010/07/18/php-function-to-get-current-svn-id/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 12:16:40 +0000</pubDate>
		<dc:creator>Christoffer Kjølbæk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://ostehamster.dk/blog/?p=960</guid>
		<description><![CDATA[Make a function like the below in you PHP file

function get_rev&#40;&#41; &#123;
	return &#40;int&#41;substr&#40;substr&#40;'$Rev: 168 $', 6&#41;, 0, -2&#41;;
&#125;

And add the Revision keyword to the properties of the file

svn propset svn:keywords Revision your_file.php

"$Rev: 168 $" will then automatically be updated on every commit.
]]></description>
			<content:encoded><![CDATA[<p>Make a function like the below in you PHP file</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_rev<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$Rev: 168 $'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And add the Revision keyword to the properties of the file</p>

<div class="wp_syntax"><div class="code"><pre class="pre" style="font-family:monospace;">svn propset svn:keywords Revision your_file.php</pre></div></div>

<p>"$Rev: 168 $" will then automatically be updated on every commit.</p>
]]></content:encoded>
			<wfw:commentRss>http://ostehamster.dk/blog/index.php/2010/07/18/php-function-to-get-current-svn-id/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making &#8220;backtrace&#8221; in MySQL with &#8220;recursive&#8221; call</title>
		<link>http://ostehamster.dk/blog/index.php/2010/04/11/making-backtrace-in-mysql-with-recursive-call/</link>
		<comments>http://ostehamster.dk/blog/index.php/2010/04/11/making-backtrace-in-mysql-with-recursive-call/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 13:00:47 +0000</pubDate>
		<dc:creator>Christoffer Kjølbæk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://ostehamster.dk/blog/?p=777</guid>
		<description><![CDATA[Having items mapped in a tree structure is often used in database design, using "child" and "parent" ids or "nodes" and "leaf nodes". Often when presenting data, it is nice to make a "backtrace" by showing all nodes from the leaf to the root of the tree.
In this case I have a system with a [...]]]></description>
			<content:encoded><![CDATA[<p>Having items mapped in a tree structure is often used in database design, using "child" and "parent" ids or "nodes" and "leaf nodes". Often when presenting data, it is nice to make a "backtrace" by showing all nodes from the leaf to the root of the tree.</p>
<p>In this case I have a system with a lot of users, each of which is mapped to a group. The groups are defined as a tree structure, but because of the roles of the system, the leaf node can never be more than three nodes away from the root. I need to show a list of, say all users not logged in the last 2 months, and the list should show in which groups the users is located.</p>
<p>I could find all users, get the group id from each users and with a recursive function in the application, find the parent group id of the group, get this group from the database, find the parent group id of the group, get this group from the database..... This would require a lot of database activity. It is also possible to make <a href="http://www.developersdex.com/gurus/articles/112.asp">nested sets</a> or <a href="http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html">stored procedures</a>, but if the depth of the three is relative low (and known), I believe the below is simpler.</p>
<p>The table of groups is defined as:</p>

<div class="wp_syntax"><div 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> <span style="color: #ff0000;">`groups`</span> <span style="color: #66cc66;">&#40;</span>
	<span style="color: #ff0000;">`gid`</span> INT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">,</span>
	<span style="color: #ff0000;">`pgid`</span> INT <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: #ff0000;">`title`</span> VARCHAR<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">100</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;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> MYISAM ;</pre></div></div>

<p>With these groups:</p>
<pre>mysql> select * from groups;
+-----+------+---------+
| gid | pgid | title   |
+-----+------+---------+
|   1 |    0 | Level 1 |
|   2 |    1 | Level 2 |
|   3 |    2 | Level 3 |
|   4 |    3 | Level 4 |
|   5 |    4 | Level 5 |
+-----+------+---------+
5 rows in set (0.00 sec)
</pre>
<p>With the below query, it is possible to make the backtrace using joins. Line 6 will find the record holding the parent group of the selected group as the temporary record bt1. Line 7 will then use the parent group id from bt1 to find this group as bt2, and so on.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> groups<span style="color: #66cc66;">.</span>gid<span style="color: #66cc66;">,</span> groups<span style="color: #66cc66;">.</span>title<span style="color: #66cc66;">,</span> 
	bt1<span style="color: #66cc66;">.</span>gid <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'gid-1'</span><span style="color: #66cc66;">,</span> bt1<span style="color: #66cc66;">.</span>title <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'title-1'</span><span style="color: #66cc66;">,</span> 
	bt2<span style="color: #66cc66;">.</span>gid <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'gid-2'</span><span style="color: #66cc66;">,</span> bt2<span style="color: #66cc66;">.</span>title <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'title-2'</span><span style="color: #66cc66;">,</span> 
	bt3<span style="color: #66cc66;">.</span>gid <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'gid-3'</span><span style="color: #66cc66;">,</span> bt3<span style="color: #66cc66;">.</span>title <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'title-3'</span>
<span style="color: #993333; font-weight: bold;">FROM</span> groups
	<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> groups <span style="color: #993333; font-weight: bold;">AS</span> bt1 <span style="color: #993333; font-weight: bold;">ON</span> bt1<span style="color: #66cc66;">.</span>gid <span style="color: #66cc66;">=</span> groups<span style="color: #66cc66;">.</span>pgid
	<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> groups <span style="color: #993333; font-weight: bold;">AS</span> bt2 <span style="color: #993333; font-weight: bold;">ON</span> bt2<span style="color: #66cc66;">.</span>gid <span style="color: #66cc66;">=</span> bt1<span style="color: #66cc66;">.</span>pgid
	<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> groups <span style="color: #993333; font-weight: bold;">AS</span> bt3 <span style="color: #993333; font-weight: bold;">ON</span> bt3<span style="color: #66cc66;">.</span>gid <span style="color: #66cc66;">=</span> bt2<span style="color: #66cc66;">.</span>pgid
<span style="color: #993333; font-weight: bold;">WHERE</span> groups<span style="color: #66cc66;">.</span>gid <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>The result is</p>
<pre>+-----+---------+-------+---------+-------+---------+-------+---------+
| gid | title   | gid-1 | title-1 | gid-2 | title-2 | gid-3 | title-3 |
+-----+---------+-------+---------+-------+---------+-------+---------+
|   1 | Level 1 |  NULL | NULL    |  NULL | NULL    |  NULL | NULL    |
|   2 | Level 2 |     1 | Level 1 |  NULL | NULL    |  NULL | NULL    |
|   3 | Level 3 |     2 | Level 2 |     1 | Level 1 |  NULL | NULL    |
|   4 | Level 4 |     3 | Level 3 |     2 | Level 2 |     1 | Level 1 |
|   5 | Level 5 |     4 | Level 4 |     3 | Level 3 |     2 | Level 2 |
+-----+---------+-------+---------+-------+---------+-------+---------+
5 rows in set (0.00 sec)</pre>
<p>This is not really a recursive call as the title says, but the result is the same, though much faster :)</p>
]]></content:encoded>
			<wfw:commentRss>http://ostehamster.dk/blog/index.php/2010/04/11/making-backtrace-in-mysql-with-recursive-call/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fast way to find the difference between two numbers</title>
		<link>http://ostehamster.dk/blog/index.php/2009/11/03/fast-way-to-to-difference-between-two-numbers/</link>
		<comments>http://ostehamster.dk/blog/index.php/2009/11/03/fast-way-to-to-difference-between-two-numbers/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 22:52:05 +0000</pubDate>
		<dc:creator>Christoffer Kjølbæk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://ostehamster.dk/blog/index.php/2009/11/03/fast-way-to-to-difference-between-two-numbers/</guid>
		<description><![CDATA[
< ?php
function diff($a, $b) {
   return ($a < $b) ? ($b - $a) : ($a - $b);
}
?>

Update: Apparently I was to tired when I wrote this, a lot faster method is like Søren mentions: abs($a-$b) :)
]]></description>
			<content:encoded><![CDATA[<p><del datetime="2009-11-04T19:38:01+00:00"><code><br />
< ?php<br />
function diff($a, $b) {<br />
   return ($a < $b) ? ($b - $a) : ($a - $b);<br />
}<br />
?><br />
</code></del></p>
<p><strong>Update:</strong> Apparently I was to tired when I wrote this, a lot faster method is like Søren mentions: <code>abs($a-$b)</code> :)</p>
]]></content:encoded>
			<wfw:commentRss>http://ostehamster.dk/blog/index.php/2009/11/03/fast-way-to-to-difference-between-two-numbers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Howto use Eclipse with PHP and SVN in Ubuntu 9.10</title>
		<link>http://ostehamster.dk/blog/index.php/2009/11/01/howto-use-eclipse-with-php-and-svn-in-ubuntu-9-10/</link>
		<comments>http://ostehamster.dk/blog/index.php/2009/11/01/howto-use-eclipse-with-php-and-svn-in-ubuntu-9-10/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 15:58:18 +0000</pubDate>
		<dc:creator>Christoffer Kjølbæk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Karmic Koala]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[Ubuntu 9.10]]></category>

		<guid isPermaLink="false">http://ostehamster.dk/blog/?p=473</guid>
		<description><![CDATA[This little guide will show how to set up Eclipse for developing PHP sites using PHP Development Tools Project and Subversion.
Install Eclipse Galileo from repository:
sudo apt-get install eclipse
A number of dependencies are required inside Eclipse, which has to be added. Start Eclipse from the menu, and select Help > Install new software... The below list [...]]]></description>
			<content:encoded><![CDATA[<p>This little guide will show how to set up Eclipse for developing PHP sites using <a href="http://www.eclipse.org/pdt/">PHP Development Tools Project</a> and Subversion.</p>
<p>Install Eclipse Galileo from repository:</p>
<blockquote><p>sudo apt-get install eclipse</p></blockquote>
<p>A number of dependencies are required inside Eclipse, which has to be added. Start Eclipse from the menu, and select Help > Install new software... The below list of update sites has to be added, which is done be typing the URL in "Work with", click Add and then type the name in the name field followed by Ok. Do this for the below update sites (name followed by URL):</p>
<p>EMF, <code>http://download.eclipse.org/modeling/emf/updates/releases/</code><br />
MyLyn, <code>http://download.eclipse.org/tools/mylyn/update/e3.4/</code><br />
GEF, <code>http://download.eclipse.org/tools/gef/updates/releases/</code><br />
DLTK, <code>http://download.eclipse.org/releases/galileo/</code><br />
Webtool, <code>http://download.eclipse.org/webtools/updates/</code></p>
<p><strong>PDT</strong><br />
Add <code>http://download.eclipse.org/tools/pdt/updates/2.0/</code> with name PDT. Open "PDT SDK 2.1.2" and select "PHP Development Tools (PDT) Runtime Feature", click Next twice, accept the license and click Finish.</p>
<p><strong>Subclipse</strong><br />
SVN integration (or one of them) in Eclipse is called <a href="http://subclipse.tigris.org/">Subclipse</a> and is installed through update sites as well.  Select Help > Install new software... and add <code>http://subclipse.tigris.org/update_1.6.x</code> into the "Work with" field and click Add type "Subclipse" in name and click Ok. Select all three options and click Next, Next, accept License and click Finish.</p>
<p><strong>Checking out a project</strong><br />
Select File -> New -> Other in the new window select SVN -> Checkout Projects from SVN and click Next.</p>
<p>Select "Create a new repository location", click Next. Type SVN repository in URL, click Next. Type username and password if required. Select the part of the repository containing the project, click Finish.</p>
<p>If the repository not already holds project settings for Eclipse, select "Check out as a project configured using the New Project Wizard" and click Finish. In the New Project Wizard select PHP -> PHP Project and click Next. Give the project a name and you are ready to go - have fun! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://ostehamster.dk/blog/index.php/2009/11/01/howto-use-eclipse-with-php-and-svn-in-ubuntu-9-10/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP highlight bug in jEdit</title>
		<link>http://ostehamster.dk/blog/index.php/2007/05/21/php-highlight-bug-in-jedit/</link>
		<comments>http://ostehamster.dk/blog/index.php/2007/05/21/php-highlight-bug-in-jedit/#comments</comments>
		<pubDate>Mon, 21 May 2007 19:33:23 +0000</pubDate>
		<dc:creator>Christoffer Kjølbæk</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://ostehamster.dk/wordpress/?p=30</guid>
		<description><![CDATA[For a long time, I have been experiencing a bug in the PHP highlightning in jEdit. The problem is when writting something like
$foo = "bar\"";
the highlightning ignores \" and start looking for the ending of the "".
This page gives the answer to my problem.
In Ubuntu Feisty Fawn, with jEdit installed with the Java-installer, the file [...]]]></description>
			<content:encoded><![CDATA[<p>For a long time, I have been experiencing a bug in the PHP highlightning in jEdit. The problem is when writting something like</p>
<blockquote><p>$foo = "bar\"";</p></blockquote>
<p>the highlightning ignores \" and start looking for the ending of the "".</p>
<p><a href="http://community.jedit.org/?q=node/view/3501">This page</a> gives the answer to my problem.</p>
<p>In Ubuntu Feisty Fawn, with jEdit installed with the Java-installer, the file is here:</p>
<blockquote><p>/usr/local/share/jedit/4.3pre9/modes/php.xml</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ostehamster.dk/blog/index.php/2007/05/21/php-highlight-bug-in-jedit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
