<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Yet another blog about PHP, HTML and CSS</title>
	
	<link>http://blog.pepa.info</link>
	<description>Petr 'PePa' Pavel</description>
	<lastBuildDate>Thu, 19 Aug 2010 18:17:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/YetAnotherBlogAboutPhpHtmlAndCss" /><feedburner:info uri="yetanotherblogaboutphphtmlandcss" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Strong random password with a bookmarklet</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/d5eO9vmoDO0/</link>
		<comments>http://blog.pepa.info/php-html-css/tools/strong-random-password-with-a-bookmarklet/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 18:17:58 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=169</guid>
		<description><![CDATA[I create all sorts of passwords rather often, be it for me or for my clients. Until today, I always sort of let my hands use the free-fall feature and generated some random characters just by dropping them onto the keyboard. Then I added upper/lower case character and a symbol here and there. I tried [...]]]></description>
			<content:encoded><![CDATA[<p>I create all sorts of passwords rather often, be it for me or for my clients. Until today, I always sort of let my hands use the free-fall feature and generated some random characters just by dropping them onto the keyboard. Then I added upper/lower case character and a symbol here and there. I tried to use random password generators before but the above procedure was always faster than locating and executing a special-purpose application. Well, today it occurred to me that a bookmarklet would be a much better solution. The browser is always running and having the bookmarklet in the bookmark toolbar makes using it a single-click job.</p>
<p><span id="more-169"></span>So, you know the drill. Drag this onto your bookmark toolbar:</p>
<p><a href="javascript:(function(){var passLength = 15; var str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&amp;*()_-+=.,[]{}:;'; var getRandomInt = function (max) { return Math.floor(Math.random() * (max + 1)); }; var newStr = '', rand = 0; while (str.length) { rand = getRandomInt(str.length-1); newStr += str.charAt(rand); str = str.substring(0, rand)+str.substr(rand+1); } prompt('Password', newStr.substr(0, passLength));})();">Random Password</a></p>
<p>It uses code from <a href="http://phpjs.org/functions/str_shuffle:529">str_shuffle()</a> (project php.js) &#8211; thanks guys!</p>
<p>You can edit the javascript code and change the set of characters that are used in the password (str). You can also change the password length there (passLength).</p>
<p>I did search the web for an existing solution before writing my own. I found quite a few bookmarklets that generate a unique password based on your master password and the place that you want to use the password for. It wasn&#8217;t my case. I needed passwords for new ftp or mysql users, this kind of stuff.</p>
<p>To be honest, I haven&#8217;t tested it in anything else than Firefox, the only true browser ;-)</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/d5eO9vmoDO0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/tools/strong-random-password-with-a-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/tools/strong-random-password-with-a-bookmarklet/</feedburner:origLink></item>
		<item>
		<title>Baking with XAMPP on Windows</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/100tFdBatSk/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/baking-with-xampp-on-windows/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 20:05:06 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=153</guid>
		<description><![CDATA[I&#8217;m not sure if it&#8217;s just my set-up but when I run cake.bat and say, try to bake a model I get &#160; Fatal error: Call to undefined function mysqli_connect() in C:\&#8230;\cake\libs\model\datasources\dbo\dbo_mysqli.php on line 73 &#160; The reason is that php.exe when run from a command line uses a different php.ini than PHP that&#8217;s run [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure if it&#8217;s just my set-up but when I run cake.bat and say, try to bake a model I get</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Fatal error: Call to undefined function mysqli_connect() in C:\&#8230;\cake\libs\model\datasources\dbo\dbo_mysqli.php on line 73
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>The reason is that php.exe when run from a command line uses a different php.ini than PHP that&#8217;s run as an Apache module. To fix this edit cake.bat and add <code>-c"C:\xampp\apache\bin\php.ini"</code>. This is the path where XAMPP placed php.ini.</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/100tFdBatSk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/baking-with-xampp-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/baking-with-xampp-on-windows/</feedburner:origLink></item>
		<item>
		<title>Getting rid of JOINs in updateAll() query</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/nqLLPkvmkF4/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/getting-rid-of-joins-in-updateall-query/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 21:28:24 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=144</guid>
		<description><![CDATA[I guess I haven&#8217;t mastered the model relationships enough in order to appreciate them &#8211; and use correctly. On one hand they seem to be really cool and provide an easy access to linked database records while on the other hand, they just seem to stand in the way too often. Caring about database queries [...]]]></description>
			<content:encoded><![CDATA[<p>I guess I haven&#8217;t mastered the model relationships enough in order to appreciate them &#8211; and use correctly. On one hand they seem to be really cool and provide an easy access to linked database records while on the other hand, they just seem to stand in the way too often.<br />
<span id="more-144"></span><br />
Caring about database queries performance as I am I find myself unbinding models more often than I might be binding them. I guess I should not set default binding in the model but that&#8217;s just a natural place to put the logic. I&#8217;m trying to follow <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> as much as possible.</p>
<p>Anyway, here&#8217;s a piece of code that unbinds all belongsTo models in order to remove JOINs from an updateAll() query.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$content</span> = <span class="kw2">new</span> Content<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$content</span>-&gt;<span class="me1">unbindModel</span><span class="br0">&#40;</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;belongsTo&#8217;</span> =&gt; <a href="http://www.php.net/array_keys"><span class="kw3">array_keys</span></a><span class="br0">&#40;</span><span class="re0">$content</span>-&gt;<span class="me1">belongsTo</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$content</span>-&gt;<span class="me1">updateAll</span><span class="br0">&#40;</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;num_of_purchases&#8217;</span> =&gt; <span class="st0">&#8216;num_of_purchases+1&#8242;</span><span class="br0">&#41;</span>, <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;id&#8217;</span> =&gt; <span class="re0">$purchasedContentIds</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>(suggested by <a href="http://groups.google.com/group/cake-php/browse_thread/thread/f51ee496aafdff23">Serge Rodovnichenko</a>)</p>
<p>Setting $content-&gt;recursive = -1 doesn&#8217;t work. I debugged the call in CakePHP 1.2.5.</p>
<p><strong>Edit September 27th, 2009:</strong><br />
Let&#8217;s move this up to another level &#8211; let&#8217;s override the default updateAll() and add support for recursive = -1. Add this to your app_model.php</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp;* A workaround for CakePHP lack of support for recursive</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp;*/</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="kw2">function</span> updateAll<span class="br0">&#40;</span><span class="re0">$fields</span>, <span class="re0">$conditions</span> = <span class="kw2">true</span>, <span class="re0">$recursive</span> = <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$recursive</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="re0">$recursive</span> = <span class="re0">$this</span>-&gt;<span class="me1">recursive</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$recursive</span> == <span class="nu0">-1</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">unbindModel</span><span class="br0">&#40;</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;belongsTo&#8217;</span> =&gt; <a href="http://www.php.net/array_keys"><span class="kw3">array_keys</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">belongsTo</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;hasOne&#8217;</span> =&gt; <a href="http://www.php.net/array_keys"><span class="kw3">array_keys</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">hasOne</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">return</span> parent::<span class="me2">updateAll</span><span class="br0">&#40;</span><span class="re0">$fields</span>, <span class="re0">$conditions</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/nqLLPkvmkF4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/getting-rid-of-joins-in-updateall-query/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/getting-rid-of-joins-in-updateall-query/</feedburner:origLink></item>
		<item>
		<title>Alternative icon for Eclipse IDE</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/2LbfGl9sI2k/</link>
		<comments>http://blog.pepa.info/php-html-css/tools/alternative-icon-for-eclipse-ide/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 09:52:01 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=136</guid>
		<description><![CDATA[Each year we have the pleasure of switching to a new version of Eclipse. And by pleasure I mean both shades of the word. Cool new features and boring migration. I usually fight my laziness for quite some time and migrate my projects gradually. Thanks folks for keeping Eclipse isolated so that I can run [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.pepa.info/wp-content/feature.gif" alt="" title="Alternative Eclipse icon" width="32" height="32" class="alignleft size-full wp-image-140" />Each year we have the pleasure of switching to a new version of Eclipse. And by pleasure I mean both shades of the word. Cool new features and boring migration. I usually fight my laziness for quite some time and migrate my projects gradually. Thanks folks for keeping Eclipse isolated so that I can run both versions simultaneously. I&#8217;m getting to my point now: I needed a new icon that would distinct the new version from the old one.<br />
<span id="more-136"></span><br />
After a proper googling I came to a conclusion that there simply isn&#8217;t one I could just download and use (ico for Windows). So I searched through the Galileo directory and found a nice gif icon:<br />
<code><br />
C:\Program Files\Eclipse 3.5 PDT\configuration\org.eclipse.osgi\bundles\162\1\.cp\feature.gif<br />
</code></p>
<p>Then I googled for an online ico creator and found <a href="http://iconverticons.com/">iConvert</a> that can not only create Windows icons but also Mac and Linux icons.<br />
Click, click and I was finally able to link my shortcut to a new icon. Perfect!</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/2LbfGl9sI2k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/tools/alternative-icon-for-eclipse-ide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/tools/alternative-icon-for-eclipse-ide/</feedburner:origLink></item>
		<item>
		<title>Duplicating sets of radio buttons with jQuery</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/3RgxainjTDc/</link>
		<comments>http://blog.pepa.info/php-html-css/jquery/duplicating-sets-of-radio-buttons-with-jquery/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 18:02:54 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=129</guid>
		<description><![CDATA[We all love the &#8220;add more&#8221; links for adding more form items to forms. More pictures to upload, more categories to add. You just name them with empty square brackets and then clone them. &#160; &#60;input type=&#34;file&#34; name=&#34;file[]&#34; value=&#34;&#34;&#62; &#60;a href=&#34;&#34; id=&#34;addMoreUploads&#34;&#62;add more&#60;/a&#62; &#160; But what if you need to clone sets of radio buttons? [...]]]></description>
			<content:encoded><![CDATA[<p>We all love the &#8220;add more&#8221; links for adding more form items to forms. More pictures to upload, more categories to add. You just name them with empty square brackets and then clone them. </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;file&quot; name=&quot;file[]&quot; value=&quot;&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;a href=&quot;&quot; id=&quot;addMoreUploads&quot;&gt;add more&lt;/a&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>But what if you need to clone sets of radio buttons? You end up with a single group of radio buttons &#8211; not with a group of radio button groups.<br />
<span id="more-129"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;div class=&quot;moreContainer&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;div class=&quot;cloneThis set&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;radio&quot; name=&quot;options[]&quot; value=&quot;1&quot;&gt; one
</div>
</li>
<li class="li2">
<div class="de2">&lt;input type=&quot;radio&quot; name=&quot;options[]&quot; value=&quot;2&quot;&gt; two
</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;radio&quot; name=&quot;options[]&quot; value=&quot;3&quot;&gt; three
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;a href=&quot;&quot; class=&quot;addMore&quot;&gt;add more&lt;/a&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>If you clone the whole cloneThis group you&#8217;ll get a group of six radio buttons but you&#8217;ll be able to choose just one.</p>
<p>Unfortunately, you have to give up the empty square brackets and start numbering them (name=&#8221;options[0]&#8220;). In the cloning function then you replace the cloned number with an ever increasing counter value.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span><span class="st0">&quot;.addMore&quot;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="kw2">var</span> parentContainer = $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">parents</span><span class="br0">&#40;</span><span class="st0">&quot;.moreContainer&quot;</span><span class="br0">&#41;</span>.<span class="me1">eq</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// the closest container (you can have nested containers too)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> cloneSource = parentContainer.<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&quot;.cloneThis&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> clonedSet = cloneSource.<span class="me1">clone</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="co1">// duplicate the set of form items</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> itemsCount = parentContainer.<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&quot;.set&quot;</span><span class="br0">&#41;</span>.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// count # of already duplicated sets</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="coMULTI">/*</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp;* Increment index of each for item</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp;* we can&#8217;t use [] because of radio buttons</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; clonedSet.<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&quot;input&quot;</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>index, element<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw1">this</span>.<span class="kw3">name</span>.<span class="me1">replace</span><span class="br0">&#40;</span><span class="re0">/\<span class="br0">&#91;</span><span class="nu0">0</span>\<span class="br0">&#93;</span>/</span>, <span class="st0">&quot;[&quot;</span>+itemsCount+<span class="st0">&quot;]&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// &nbsp; &nbsp;$(element).val(itemsCount); // this works as a debugger for type=&quot;text&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; clonedSet.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">&quot;cloneThis&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// remove class &#8216;cloneThis&#8217; to avoid duplicating it in the next round</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// &nbsp; &nbsp;clonedSet.find(&quot;input[name*='zoom'][value=3]&quot;).attr(&quot;checked&quot;, true); ;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// use this syntax to set a default value</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; cloneSource.<span class="me1">after</span><span class="br0">&#40;</span>clonedSet<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>This function is generic and works for any set of input fields (not textarea and select though). You can have many &#8220;add this&#8221; and &#8220;add that&#8221; on a single page and still use the same function. You just have to switch from using id to class for identifying the containers, links and cloning sources.</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/3RgxainjTDc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/jquery/duplicating-sets-of-radio-buttons-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/jquery/duplicating-sets-of-radio-buttons-with-jquery/</feedburner:origLink></item>
		<item>
		<title>MySQL comparison catch: ‘abc’ = 00</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/03Xx2K11c-Q/</link>
		<comments>http://blog.pepa.info/php-html-css/programming-techniques/mysql-comparison-catch-abc-00/#comments</comments>
		<pubDate>Mon, 25 May 2009 20:39:00 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Programming Techniques]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=113</guid>
		<description><![CDATA[I was shocked to find a weakness in my authentication library today. It was possible to get around the password check if you knew the username. All you had to do was to enter 00 as the password. Or you just entered 00 as the username too and you got authenticated as the first user. [...]]]></description>
			<content:encoded><![CDATA[<p>I was shocked to find a weakness in my authentication library today. It was possible to get around the password check if you knew the username. All you had to do was to enter 00 as the password. Or you just entered 00 as the username too and you got authenticated as the first user.<br />
<span id="more-113"></span><br />
The bug was a combination of these three things:</p>
<ol>
<li>A password (or/and username) that doesn&#8217;t contain any numbers</li>
<li>MySQL type conversion in conditions &#8211; when comparing a VARCHAR column to an INTEGER value it converts VARCHAR to INTEGER, not the other way around.</li>
<li>My own database wrapper was trying to be smart and didn&#8217;t wrap numeric values with apostrophes</li>
</ol>
<p>Consider this template:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">SELECT</span> <span class="nu0">1</span> <span class="kw1">FROM</span> my_users <span class="kw1">WHERE</span> <span class="br0">&#40;</span>username = %s<span class="br0">&#41;</span> <span class="kw1">AND</span> <span class="br0">&#40;</span>password = %s<span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>and something along these PHP lines:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;username&#8217;</span><span class="br0">&#93;</span> &amp;&amp; <span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;password&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// will catch 0 but not 00</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>mysqlValue<span class="br0">&#40;</span><span class="re0">$sqlTemplate</span>, <span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;username&#8217;</span><span class="br0">&#93;</span>, <span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;password&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;welcome&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;wrong password&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>I won&#8217;t go into details about <code>mysqlValue()</code>. The important part is that it checks for special cases of NULL, true, false and is_numeric() and runs the rest through mysql_real_escape_string(). Then it inserts all parameters into the template using vprintf().</p>
<p>The problem is with is_numeric(). After being evaluated as a numeric value, &#8217;00&#8242; is entered into the query without apostrophes.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">SELECT</span> <span class="nu0">1</span> <span class="kw1">FROM</span> my_users <span class="kw1">WHERE</span> <span class="br0">&#40;</span>username = <span class="st0">&#8216;my_username&#8217;</span><span class="br0">&#41;</span> <span class="kw1">AND</span> <span class="br0">&#40;</span>password = <span class="nu0">00</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>And because any varchar that doesn&#8217;t contain a number compared to an integer is evaluated as true the result is a catastrophe.</p>
<p><code>'abc' = 00</code> is evaluated as true. <code>'abc1' = 00</code> would be false however, unfortunately only few users append a number to their password. If you use 00 for both the username and the password you get authenticated as the first user who didn&#8217;t do so.</p>
<p>Check out this <a href="http://bugs.mysql.com/bug.php?id=42241">false bug report</a> or the <a href="http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html">related documentation page</a>.</p>
<h2>Why you could want to pass numeric values without apostrophes</h2>
<p>I wonder myself :-) Here are some reasons I remembered:</p>
<ul>
<li>I need to pass NULL in some cases and for that I can&#8217;t use %d
<li>Using apostrophes for integer comparison (1 = &#8217;1&#8242;) means unnecessary type conversion that takes time. A small amount of time but still.</li>
<li>An argument for abandoning the is_numeric() code: Using %d and %s in SQL templates provides a visual clue about what values can be expected there. But then I couldn&#8217;t insert NULL values.</li>
</ul>
<h2>So how to fix this mess?</h2>
<p>What do you think? Should I remove the is_numeric() test and replace all %d with %s in all SQL templates? Remember that <code>printf("%d", "'123'")</code> will return 0.<br />
Or should I keep the is_numeric() test and rewrite vulnerable queries to use for example CAST:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">SELECT</span> <span class="nu0">1</span> <span class="kw1">FROM</span> my_users <span class="kw1">WHERE</span> <span class="br0">&#40;</span>username = CAST<span class="br0">&#40;</span>%s <span class="kw1">AS</span> CHAR<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AND</span> <span class="br0">&#40;</span>password = CAST<span class="br0">&#40;</span>%s <span class="kw1">AS</span> CHAR<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>Update 2010-01-18: I added the real reason for wanting to preserve %s in the template.</p>
<p>Update 2010-01-20:<br />
Unfortunately, what I thought to be a solution (CAST(%s AS CHAR)) has another flaw &#8211; strips leading zeroes from the username / password which results into authentication failure.<br />
So dear reader, any ideas?</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/03Xx2K11c-Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/programming-techniques/mysql-comparison-catch-abc-00/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/programming-techniques/mysql-comparison-catch-abc-00/</feedburner:origLink></item>
		<item>
		<title>Switching layout using a url parameter</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/R4WIFKNQDJw/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/switching-a-layout-using-a-url-parameter/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 22:57:35 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=99</guid>
		<description><![CDATA[I needed to open a static page in a pop-up window. For static pages we have a handy controller Pages but I wanted to use a different layout for each page and do it in a flexible way. The magic of my solution is in three lines of code in AppController (app/app_controller.php). I simplify the [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to open a static page in a pop-up window. For static pages we have a handy controller Pages but I wanted to use a different layout for each page and do it in a flexible way.<br />
<span id="more-99"></span><br />
The magic of my solution is in three lines of code in AppController (app/app_controller.php). I simplify the code for the sake of clarity:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> AppController <span class="kw2">extends</span> Controller <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">function</span> beforeFilter<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/empty"><span class="kw3">empty</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">passedArgs</span><span class="br0">&#91;</span><span class="st0">&#8216;layout&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">layout</span> = <span class="re0">$this</span>-&gt;<span class="me1">passedArgs</span><span class="br0">&#91;</span><span class="st0">&#8216;layout&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>I created a file /app/views/layouts/popup.ctp that contains only:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span> <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$content_for_layout</span>; <span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>And I call the static page as:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http:<span class="co1">//test.com/pages/termsOfMembership/layout:popup</span></div>
</li>
</ol>
</div>
<p>Which is created using this call:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$html</span>-&gt;<span class="me1">link</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="st0">&#8216;Terms of Membership&#8217;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;Router::<span class="me2">url</span><span class="br0">&#40;</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;controller&#8217;</span> =&gt; <span class="st0">&#8216;pages&#8217;</span>, <span class="st0">&#8216;action&#8217;</span> =&gt; <span class="st0">&#8216;termsOfMembership&#8217;</span>, <span class="st0">&#8216;layout&#8217;</span> =&gt; <span class="st0">&#8216;popup&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp;<span class="st0">&#8216;default&#8217;</span> =&gt; <span class="kw2">false</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="st0">&#8216;onclick&#8217;</span> =&gt; <span class="st0">&quot;window.open(this.href);&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#41;</span>,</div>
</li>
</ol>
</div>
<p>With this setting in my /app/config/routes.php:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">Router::<span class="me2">connect</span><span class="br0">&#40;</span><span class="st0">&#8216;/pages/*&#8217;</span>, <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;controller&#8217;</span> =&gt; <span class="st0">&#8216;pages&#8217;</span>, <span class="st0">&#8216;action&#8217;</span> =&gt; <span class="st0">&#8216;display&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>That Router setting is redundant if you use urls that look like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">http:<span class="co1">//test.com/pages/display/termsOfMembership/layout:popup</span></div>
</li>
</ol>
</div>
<p>Then you also have to use a different call to the Router::url():</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;controller&#8217;</span> =&gt; <span class="st0">&#8216;pages&#8217;</span>, <span class="st0">&#8216;action&#8217;</span> =&gt; <span class="st0">&#8216;display&#8217;</span>, <span class="st0">&#8216;termsOfMembership&#8217;</span>, <span class="st0">&#8216;layout&#8217;</span> =&gt; <span class="st0">&#8216;popup&#8217;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/R4WIFKNQDJw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/switching-a-layout-using-a-url-parameter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/switching-a-layout-using-a-url-parameter/</feedburner:origLink></item>
		<item>
		<title>Dealing with different configuration for development and production box</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/RSte_3x-bA8/</link>
		<comments>http://blog.pepa.info/php-html-css/programming-techniques/different-configuration-development-production-box/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 00:16:42 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=94</guid>
		<description><![CDATA[All right, this isn&#8217;t exactly a rocket science, it&#8217;s just something I use and find very handy. We all develop (and test) on one computer and deploy to a different computer to make the changes live. Having to run the application in two different environments brings a challenge of using different configuration based on where [...]]]></description>
			<content:encoded><![CDATA[<p>All right, this isn&#8217;t exactly a rocket science, it&#8217;s just something I use and find very handy.</p>
<p>We all develop (and test) on one computer and deploy to a different computer to make the changes live. Having to run the application in two different environments brings a challenge of using different configuration based on where the application runs.<br />
<span id="more-94"></span></p>
<h3>Multiple configuration files</h3>
<p>I started by having two configuration files, one for my dev box and another for the production server. They were named the same and I had one on my dev box and one on the server. Each deployment though, meant that I had to be careful not to overwrite the server file with my local copy. That ruled out using a simple synchronization script like lftp or <a title="feature Keep Remote Directory Up To Date" href="http://winscp.net/eng/docs/task_keep_up_to_date" target="_blank">WinScp</a>.</p>
<p>The simplest solution is to name the configuration files differently and upload them both to both servers. All right, even simpler is to have a single configuration php file and define different values using if/else but that can quickly get out of hands as the number of variables grows.</p>
<p>If you need to upload to more production servers (more than one customer) you need to use some more sophisticated deployment script (Ant?).</p>
<p>Let&#8217;s return to the simple solution for now. You need to find a piece of information that can be used as a computer identifier and use it to choose the right set of configuration data.</p>
<h3>$_SERVER['SERVER_NAME'] &amp; $_SERVER['SERVER_ADDR']</h3>
<p>You can use these two for most situations. I develop on my workstation and I have set up domain name based web hosts (C:\xampp\apache\conf\extra\httpd-vhosts.conf) using fake domains (C:\WINDOWS\system32\drivers\etc\hosts).</p>
<p>Using $_SERVER['SERVER_NAME'] works when you know it up front but sometimes your client is going to choose it just before launching the site. Or he decides to change it later on. Not a big deal but I don&#8217;t like chaos.</p>
<p>$_SERVER['SERVER_ADDR'] is also fine but don&#8217;t forget to change it when your production server&#8217;s ip address changes. Not an issue if you use just two computers with 127.0.0.1 and &#8220;else&#8221;.</p>
<h3>Running scripts locally</h3>
<p>Sometimes you need to run a script locally as an extra level of security. Say you run a cron job and you don&#8217;t want public to mess with it by running it off schedule. So you run it as http://localhost/tadada.php and check for SERVER_NAME/ADDR to make sure it was indeed run that way. But then your cannot use it for picking the right configuration set.</p>
<h3>getenv(&#8220;COMPUTERNAME&#8221;) to the rescue</h3>
<p>This value is unlikely to change during the lifetime of your application and doesn&#8217;t change based on the way you run it. The drawback is that not all servers define this variable so you may have to seek a different computer identificator.</p>
<p>What is your way of dealing with configuration sets?</p>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/RSte_3x-bA8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/programming-techniques/different-configuration-development-production-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/programming-techniques/different-configuration-development-production-box/</feedburner:origLink></item>
		<item>
		<title>Populating a SELECT box with distinct values</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/gtRoDDl4MGk/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/populating-a-select-box-with-distinct-values/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 22:13:24 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=90</guid>
		<description><![CDATA[Let&#8217;s say you log events into a database table Log. Attribute event holds event type and you want to filter the log listing just by that. Here&#8217;s what you probably try at first: &#160; $this-&#62;set&#40;&#8216;events&#8217;, &#160; $this-&#62;Log-&#62;find&#40;&#8216;list&#8217;, &#160; &#160; array&#40;&#8216;fields&#8217; =&#62; &#8216;DISTINCT Log.event&#8217;, &#8216;Log.event&#8217;&#41;&#41;&#41;; &#160; It&#8217;s not gonna work and you will have to use [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you log events into a database table Log. Attribute <i>event</i> holds event type and you want to filter the log listing just by that.</p>
<p>Here&#8217;s what you probably try at first:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$this</span>-&gt;<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&#8216;events&#8217;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$this</span>-&gt;<span class="me1">Log</span>-&gt;<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&#8216;list&#8217;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;fields&#8217;</span> =&gt; <span class="st0">&#8216;DISTINCT Log.event&#8217;</span>, <span class="st0">&#8216;Log.event&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>It&#8217;s not gonna work and you will have to use find(&#8216;all&#8217;) and Set::combine() to get what you want:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$events</span> = <span class="re0">$this</span>-&gt;<span class="me1">Log</span>-&gt;<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&#8216;all&#8217;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;fields&#8217;</span> =&gt; <span class="st0">&#8216;DISTINCT Log.event&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$this</span>-&gt;<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">&#8216;events&#8217;</span>, </div>
</li>
<li class="li2">
<div class="de2">&nbsp; Set::<span class="me2">combine</span><span class="br0">&#40;</span><span class="re0">$events</span>, <span class="st0">&#8216;{n}.Log.event&#8217;</span>, <span class="st0">&#8216;{n}.Log.event&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/gtRoDDl4MGk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/populating-a-select-box-with-distinct-values/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/populating-a-select-box-with-distinct-values/</feedburner:origLink></item>
		<item>
		<title>SQL functions or keywords in CakePHP conditions</title>
		<link>http://feedproxy.google.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~3/I3-vJrLGXao/</link>
		<comments>http://blog.pepa.info/php-html-css/cakephp/sql-functions-or-keywords-in-cakephp-conditions/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 13:21:09 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=84</guid>
		<description><![CDATA[For those who missed the information, starting from CakePHP 1.2 it is no longer possible to use the magic tag -! in your condition to prevent your SQL function or keyword to be enclosed in quotes. The recommended way now is to place it into the key or not make the array associative at all. [...]]]></description>
			<content:encoded><![CDATA[<p>For those who missed the information, <a title="changeset details" href="https://trac.cakephp.org/changeset/5139" target="_blank">starting from CakePHP 1.2</a> it is no longer possible to use the magic tag -! in your condition to prevent your SQL function or keyword to be enclosed in quotes.</p>
<p>The recommended way now is to place it into the key or not make the array associative at all. It is no longer possible to put it into the value part of the definition.</p>
<p>So instead of:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&#8216;DATE_ADD(Payment.modified, INTERVAL 2 DAY) &gt;&#8217;</span> =&gt; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&#8216;CURRENT_DATE&#8217;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>you have to use:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&#8216;DATE_ADD(Payment.modified, INTERVAL 2 DAY) &gt; CURRENT_DATE&#8217;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/YetAnotherBlogAboutPhpHtmlAndCss/~4/I3-vJrLGXao" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/cakephp/sql-functions-or-keywords-in-cakephp-conditions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.pepa.info/php-html-css/cakephp/sql-functions-or-keywords-in-cakephp-conditions/</feedburner:origLink></item>
	</channel>
</rss>
