<?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>Gabriel de Kadt &#187; random</title>
	<atom:link href="http://www.lazydada.com/tag/random/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lazydada.com</link>
	<description>Personal notes on Mac based web development and design.</description>
	<lastBuildDate>Tue, 30 Aug 2011 10:47:39 +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>Random content rotation using PHP</title>
		<link>http://www.lazydada.com/2008-10-22/random-content-rotation-using-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=random-content-rotation-using-php</link>
		<comments>http://www.lazydada.com/2008-10-22/random-content-rotation-using-php/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 10:19:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web design & development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.lazydada.com/?p=127</guid>
		<description><![CDATA[I had been using a JavaScript solution from javascriptkit.com to randomly show one option from a series on a page. All the options are wrapped in DIVs and placed in a single include file. This first solution used JS to set a CSS display:none; to all but one of a series of DIVs in a [...]]]></description>
			<content:encoded><![CDATA[<p>I had been using a JavaScript solution from <a href="http://www.javascriptkit.com/script/script2/randomcontent.shtml" rel="nofollow" target="_blank"><del datetime="2008-10-22T09:40:36+00:00">javascriptkit.com</del></a> to randomly show one option from a series on a page. All the options are wrapped in DIVs and placed in a single include file. This first solution used JS to set a CSS <code>display:none;</code> to all but one of a series of DIVs in a document. Nice as it was, the resulting xHTML markup would not validate properly. <span>[UPDATE - this is due to the fact that xHTML needing extra <code><a href="http://www.lazydada.com/2008-11-07/avoid-html-validation-errors-due-to-your-javascript/" target="_blank">CDATA</a></code> markup around any JavaScript contained within.]</span> Another minus was that, although sold as plus for web-crawlers etc (all options remain in the HTML at all times), if JavaScript was off then all of the options would appear and muck-up the carefully honed design. </p>
<p>I looked for fixes to the validation issues caused by this line <code>for (var i=0; i&lt;alldivs .length; i++)</code> but to no avail. Half a day of searching later and after trying these other options I found <a href="#simple-php-random-content-rotation">the answer</a>; </p>
<ul>
<li><a href="http://www.sitepoint.com/article/random-content-rotation-made/" target="_blank" rel="nofollow"><del datetime="2008-10-22T09:40:36+00:00">CSS and Perl solution by Nigel Peck</del></a> similar in method to my first option</li>
<li>a seemingly super simple PHP solution from Greta in the comments to the above (requires splitting the options into separate files)</li>
<li>a php solution from <a href="http://www.pixel2life.com/publish/tutorials/904/php_random_content_or_advertisment/" target="_blank" rel="nofollow"><del datetime="2008-10-22T09:40:36+00:00">pixel2life.com</del></a></li>
</ul>
<h2 id="simple-php-random-content-rotation">The Answer</h2>
<p>None of these worked for me. The best (only) solution I found before the sun went down was from <a href="http://lab.artlung.com/random-content/">Joe Crawford</a>. Based on PHP&#8217;s <a href="http://www.php.net/srand"><code>srand</code></a> function<br />
 this solution allowed me to wrap PHP around the include file with the options and bingo; it works. As this is server side now &#8211; only one DIV will be in the HTML so no problem if JavaScript is off. </p>
<p>Happy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lazydada.com/2008-10-22/random-content-rotation-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
