<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments for Adventures in PHP / DHTML / CSS and MySQL</title>
	<atom:link href="http://pureform.wordpress.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://pureform.wordpress.com</link>
	<description>Adventures in PHP / DHTML / CSS and MySQL</description>
	<lastBuildDate>Thu, 12 Nov 2009 09:41:53 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on Never use ORDER BY RAND() again! by Anze</title>
		<link>http://pureform.wordpress.com/2008/03/05/never-use-order-by-rand-again/#comment-454</link>
		<dc:creator>Anze</dc:creator>
		<pubDate>Thu, 12 Nov 2009 09:41:53 +0000</pubDate>
		<guid isPermaLink="false">http://pureform.wordpress.com/?p=10#comment-454</guid>
		<description>It might be better to use rand(1,numPK) and get rid of one select. Then if the last query fails you can rerun it with id&gt;randPK. 
In worst case this solution is equivalent to yours, in best case it saves one select. 
Of course, this is only true because the selects are more or less equally expensive. 

But this does not really matter, because the distribution of this approach is not even. If you have ids 1,2 and 4 then &#039;2&#039; is twice as likely to be chosen. This is the reason I haven&#039;t mentioned this approach - it is not random. 

There are up to 10 different approaches, and they all suck one way or the other. :)

Another one is:
  select count(*) from mytable
  $rand=rand(1,numRec)
  select * from mytable order by id limit $rand,1

BUT please don&#039;t use this. Yes you can use &#039;where&#039; with it. Yes you can have holes. Yes it is simple. Yes you can get more IDs at once, if you build a function that returns N different randoms from X values. Yes the distribution is even.
But it is also (probably) terribly inefficient. In worst case it is probably as inefficient as rand(). If you must take this approach, at least benchmark it. i haven&#039;t done it because... Well, I think it is inefficient. :) But yes, MySQL could optimize that kind of query, so YMMV.</description>
		<content:encoded><![CDATA[<p>It might be better to use rand(1,numPK) and get rid of one select. Then if the last query fails you can rerun it with id&gt;randPK.<br />
In worst case this solution is equivalent to yours, in best case it saves one select.<br />
Of course, this is only true because the selects are more or less equally expensive. </p>
<p>But this does not really matter, because the distribution of this approach is not even. If you have ids 1,2 and 4 then &#8216;2&#8242; is twice as likely to be chosen. This is the reason I haven&#8217;t mentioned this approach &#8211; it is not random. </p>
<p>There are up to 10 different approaches, and they all suck one way or the other. :)</p>
<p>Another one is:<br />
  select count(*) from mytable<br />
  $rand=rand(1,numRec)<br />
  select * from mytable order by id limit $rand,1</p>
<p>BUT please don&#8217;t use this. Yes you can use &#8216;where&#8217; with it. Yes you can have holes. Yes it is simple. Yes you can get more IDs at once, if you build a function that returns N different randoms from X values. Yes the distribution is even.<br />
But it is also (probably) terribly inefficient. In worst case it is probably as inefficient as rand(). If you must take this approach, at least benchmark it. i haven&#8217;t done it because&#8230; Well, I think it is inefficient. :) But yes, MySQL could optimize that kind of query, so YMMV.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Never use ORDER BY RAND() again! by pureform</title>
		<link>http://pureform.wordpress.com/2008/03/05/never-use-order-by-rand-again/#comment-453</link>
		<dc:creator>pureform</dc:creator>
		<pubDate>Wed, 11 Nov 2009 20:24:13 +0000</pubDate>
		<guid isPermaLink="false">http://pureform.wordpress.com/?p=10#comment-453</guid>
		<description>I agree with you 100%... this is great if you don&#039;t have holes in your PKs.... and now since I do [for the same application I wrote this for, I&#039;m doing something like this:
&lt;code&gt;
maxPK = SELECT MAX(`id`) AS `maxPK` FROM `tbl`
minPK = SELECT MIN(`id`) AS `maxPK` FROM `tbl` -- Can&#039;t assume 1 is the lowest PK [primary key]
randPK = rand(minPK,numPK)
row = SELECT * FROM `tbl` WHERE `id`&lt;=randPK -- worst case scenario, it returns the last record in the DB.
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I agree with you 100%&#8230; this is great if you don&#8217;t have holes in your PKs&#8230;. and now since I do [for the same application I wrote this for, I'm doing something like this:<br />
<code><br />
maxPK = SELECT MAX(`id`) AS `maxPK` FROM `tbl`<br />
minPK = SELECT MIN(`id`) AS `maxPK` FROM `tbl` -- Can't assume 1 is the lowest PK [primary key]<br />
randPK = rand(minPK,numPK)<br />
row = SELECT * FROM `tbl` WHERE `id`&lt;=randPK &#8212; worst case scenario, it returns the last record in the DB.<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Never use ORDER BY RAND() again! by Anze</title>
		<link>http://pureform.wordpress.com/2008/03/05/never-use-order-by-rand-again/#comment-452</link>
		<dc:creator>Anze</dc:creator>
		<pubDate>Wed, 11 Nov 2009 09:52:33 +0000</pubDate>
		<guid isPermaLink="false">http://pureform.wordpress.com/?p=10#comment-452</guid>
		<description>This is indeed a simple and elegant solution - if you don&#039;t have holes in your exampleID. If some records may be missing then you have a problem. But that can be solved if you update exampleID the smart way (if you insert a record, put in max(exampleI)+1; if you delete it, get the record with highest exampleID and put the deleted record&#039;s exampleID in it). 

Also, your solution only retrieves 1 record from DB, not multiple. It can be changed to do so, though. 

But not much can help you if you have a where constraint:
select * from mytable where somefile=3 and someotherfield=5 order by rand() limit 3;

I am still looking for a solution to that case. Currently I am assigning a rand() every few minutes to some field and selecting like this:
$rand=rand(1,99999999)&#039;;
select * from mytable where somefield=3 and someotherfield=5 and randfield&gt;=$rand order by randfield limit 1

If anyone has a better idea... Do share. :)

Here is the bug report, let&#039;s hope MySQL developers step up and solve this issue for us so we don&#039;t have to reinvent this functionality:
http://bugs.mysql.com/bug.php?id=33837

You can help by voting for it (hint ;).</description>
		<content:encoded><![CDATA[<p>This is indeed a simple and elegant solution &#8211; if you don&#8217;t have holes in your exampleID. If some records may be missing then you have a problem. But that can be solved if you update exampleID the smart way (if you insert a record, put in max(exampleI)+1; if you delete it, get the record with highest exampleID and put the deleted record&#8217;s exampleID in it). </p>
<p>Also, your solution only retrieves 1 record from DB, not multiple. It can be changed to do so, though. </p>
<p>But not much can help you if you have a where constraint:<br />
select * from mytable where somefile=3 and someotherfield=5 order by rand() limit 3;</p>
<p>I am still looking for a solution to that case. Currently I am assigning a rand() every few minutes to some field and selecting like this:<br />
$rand=rand(1,99999999)&#8217;;<br />
select * from mytable where somefield=3 and someotherfield=5 and randfield&gt;=$rand order by randfield limit 1</p>
<p>If anyone has a better idea&#8230; Do share. :)</p>
<p>Here is the bug report, let&#8217;s hope MySQL developers step up and solve this issue for us so we don&#8217;t have to reinvent this functionality:<br />
<a href="http://bugs.mysql.com/bug.php?id=33837" rel="nofollow">http://bugs.mysql.com/bug.php?id=33837</a></p>
<p>You can help by voting for it (hint ;).</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Installing memcache on Windows for PHP by ravi</title>
		<link>http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/#comment-451</link>
		<dc:creator>ravi</dc:creator>
		<pubDate>Mon, 09 Nov 2009 09:59:41 +0000</pubDate>
		<guid isPermaLink="false">http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/#comment-451</guid>
		<description>wow!!!simply great, thanks alot, i really found it helpful. Can you write more examples of using memcached.</description>
		<content:encoded><![CDATA[<p>wow!!!simply great, thanks alot, i really found it helpful. Can you write more examples of using memcached.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Installing memcache on Windows for PHP by nurv7</title>
		<link>http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/#comment-450</link>
		<dc:creator>nurv7</dc:creator>
		<pubDate>Sat, 07 Nov 2009 14:10:10 +0000</pubDate>
		<guid isPermaLink="false">http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/#comment-450</guid>
		<description>gee, thank u so much guys, my memcache is working now...</description>
		<content:encoded><![CDATA[<p>gee, thank u so much guys, my memcache is working now&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Using Memcache with MySQL and PHP by jay</title>
		<link>http://pureform.wordpress.com/2008/05/21/using-memcache-with-mysql-and-php/#comment-449</link>
		<dc:creator>jay</dc:creator>
		<pubDate>Sat, 24 Oct 2009 04:20:33 +0000</pubDate>
		<guid isPermaLink="false">http://pureform.wordpress.com/?p=13#comment-449</guid>
		<description>One of the other cool things with memcached is if you are using templates in your application, you can cache the templates in memcache.  At runtime, pull the template file from the cache rather than disk.</description>
		<content:encoded><![CDATA[<p>One of the other cool things with memcached is if you are using templates in your application, you can cache the templates in memcache.  At runtime, pull the template file from the cache rather than disk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on About by Satya</title>
		<link>http://pureform.wordpress.com/about/#comment-448</link>
		<dc:creator>Satya</dc:creator>
		<pubDate>Tue, 20 Oct 2009 15:17:08 +0000</pubDate>
		<guid isPermaLink="false">#comment-448</guid>
		<description>good blog.
I liked the theme also. Only a month back I have searched a lot for a good theme.</description>
		<content:encoded><![CDATA[<p>good blog.<br />
I liked the theme also. Only a month back I have searched a lot for a good theme.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Matching a word / characters outside of html tags by Charleh</title>
		<link>http://pureform.wordpress.com/2008/01/04/matching-a-word-characters-outside-of-html-tags/#comment-447</link>
		<dc:creator>Charleh</dc:creator>
		<pubDate>Fri, 09 Oct 2009 12:50:30 +0000</pubDate>
		<guid isPermaLink="false">http://pureform.wordpress.com/2008/01/04/matching-a-word-characters-outside-of-html-tags/#comment-447</guid>
		<description>True, this doesn&#039;t work for word&gt; word word - but in HTML text a &gt; is represented by &gt; so this won&#039;t be a problem - also a lone &gt; should not be found in valid HTML.</description>
		<content:encoded><![CDATA[<p>True, this doesn&#8217;t work for word&gt; word word &#8211; but in HTML text a &gt; is represented by &gt; so this won&#8217;t be a problem &#8211; also a lone &gt; should not be found in valid HTML.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Using Memcache with MySQL and PHP by randell</title>
		<link>http://pureform.wordpress.com/2008/05/21/using-memcache-with-mysql-and-php/#comment-446</link>
		<dc:creator>randell</dc:creator>
		<pubDate>Wed, 07 Oct 2009 02:49:27 +0000</pubDate>
		<guid isPermaLink="false">http://pureform.wordpress.com/?p=13#comment-446</guid>
		<description>&quot;Memcached is a very good tool for the right job.&quot; --- yeah,,you should know when to use memcached., you can&#039;t always use memcached to replace all your queries...</description>
		<content:encoded><![CDATA[<p>&#8220;Memcached is a very good tool for the right job.&#8221; &#8212; yeah,,you should know when to use memcached., you can&#8217;t always use memcached to replace all your queries&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Installing memcache on Windows for PHP by David</title>
		<link>http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/#comment-445</link>
		<dc:creator>David</dc:creator>
		<pubDate>Wed, 23 Sep 2009 10:24:35 +0000</pubDate>
		<guid isPermaLink="false">http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/#comment-445</guid>
		<description>thanks! nice tutorial</description>
		<content:encoded><![CDATA[<p>thanks! nice tutorial</p>
]]></content:encoded>
	</item>
</channel>
</rss>
