<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Content rotation</title>
	<link>http://askmichel.icoder.com/2006/10/30/content-rotation/</link>
	<description>i Code to help you profit!</description>
	<pubDate>Thu, 11 Mar 2010 19:02:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.3</generator>

	<item>
		<title>by: michel</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-343</link>
		<pubDate>Mon, 05 Oct 2009 06:20:52 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-343</guid>
					<description>The &lt;code&gt;content-rotation.js&lt;/code&gt; script has code:
&lt;code&gt;if (content_rotation_list.length &amp;#62; 0) {
&amp;#160;&amp;#160;var url = content_rotation_list[
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style=&quot;background-color:yellow&quot;&gt;Math.floor(Math.random()*(content_rotation_list.length-1))&lt;/span&gt;
&amp;#160;&amp;#160;];&lt;/code&gt;

This code gets the URL from &lt;em&gt;content list&lt;em&gt; in random order.
You can change this code to show anoher page daily:
&lt;code&gt;if (content_rotation_list.length &amp;#62; 0) {
&amp;#160;&amp;#160;&lt;span style=&quot;color:blue&quot;&gt;var day = parseInt((new Date).valueOf()/86400000;&lt;/span&gt;
&amp;#160;&amp;#160;var url = content_rotation_list[
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style=&quot;color:blue&quot;&gt;day%content_rotation_list.length)&lt;/span&gt;
&amp;#160;&amp;#160;];&lt;/code&gt;

If you'd like change your page on reload you need to play with &lt;em&gt;cookies&lt;/em&gt;.

Hope this helps.
Michel</description>
		<content:encoded><![CDATA[<p>The <code>content-rotation.js</code> script has code:<br />
<code>if (content_rotation_list.length &gt; 0) {<br />
&nbsp;&nbsp;var url = content_rotation_list[<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:yellow">Math.floor(Math.random()*(content_rotation_list.length-1))</span><br />
&nbsp;&nbsp;];</code></p>
<p>This code gets the URL from <em>content list<em> in random order.<br />
You can change this code to show anoher page daily:<br />
<code>if (content_rotation_list.length &gt; 0) {<br />
&nbsp;&nbsp;<span style="color:blue">var day = parseInt((new Date).valueOf()/86400000;</span><br />
&nbsp;&nbsp;var url = content_rotation_list[<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">day%content_rotation_list.length)</span><br />
&nbsp;&nbsp;];</code></p>
<p>If you&#8217;d like change your page on reload you need to play with <em>cookies</em>.</p>
<p>Hope this helps.<br />
Michel
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: vvdven</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-341</link>
		<pubDate>Wed, 30 Sep 2009 12:47:49 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-341</guid>
					<description>Hello,
Thanks for your nice script, it was exactly what I was looking for.

I have just one question regarding the Java method:

Would it be possible to have the script either another page daily or upon page reload?

And if so, how would I implement this?

Thanks.</description>
		<content:encoded><![CDATA[<p>Hello,<br />
Thanks for your nice script, it was exactly what I was looking for.</p>
<p>I have just one question regarding the Java method:</p>
<p>Would it be possible to have the script either another page daily or upon page reload?</p>
<p>And if so, how would I implement this?</p>
<p>Thanks.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Nick</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-332</link>
		<pubDate>Fri, 03 Jul 2009 21:31:46 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-332</guid>
					<description>Awesome script, just what I needed. Thanks a lot!</description>
		<content:encoded><![CDATA[<p>Awesome script, just what I needed. Thanks a lot!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: gorky5</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-294</link>
		<pubDate>Wed, 29 Oct 2008 12:36:47 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-294</guid>
					<description>Ah, so simple, yet so elusive. Thanks so much Michel! I'm really grateful for your help with this - it's solved a lot of problems for me.

I'm pretty much a php newbie, with my knowledge limited to hacking around with WordPress themes. I appreciate you sharing your knowledge with others.

Joe</description>
		<content:encoded><![CDATA[<p>Ah, so simple, yet so elusive. Thanks so much Michel! I&#8217;m really grateful for your help with this - it&#8217;s solved a lot of problems for me.</p>
<p>I&#8217;m pretty much a php newbie, with my knowledge limited to hacking around with WordPress themes. I appreciate you sharing your knowledge with others.</p>
<p>Joe
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: michel</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-293</link>
		<pubDate>Tue, 28 Oct 2008 16:56:14 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-293</guid>
					<description>Hi Joe,

Lets suppose you have 365 files named as &lt;code&gt;1.html&lt;/code&gt;, &lt;code&gt;2.html&lt;/code&gt;, ..., &lt;code&gt;180.html&lt;/code&gt;, ..., &lt;code&gt;365.html&lt;/code&gt; . One file per a day of the year. Then you don't need this &lt;code&gt;content-rotation.php&lt;/code&gt; or &lt;code&gt;index.php&lt;/code&gt; files.

You can use this simple php-snippet below to include your numbered html-files into any of your php-pages:

&lt;code&gt;&amp;#60;?php
include ( date(&amp;#34;z&amp;#34;) . &amp;#34;.html&amp;#34; );
?&amp;#62;&lt;/code&gt;

Michel</description>
		<content:encoded><![CDATA[<p>Hi Joe,</p>
<p>Lets suppose you have 365 files named as <code>1.html</code>, <code>2.html</code>, &#8230;, <code>180.html</code>, &#8230;, <code>365.html</code> . One file per a day of the year. Then you don&#8217;t need this <code>content-rotation.php</code> or <code>index.php</code> files.</p>
<p>You can use this simple php-snippet below to include your numbered html-files into any of your php-pages:</p>
<p><code>&lt;?php<br />
include ( date(&quot;z&quot;) . &quot;.html&quot; );<br />
?&gt;</code></p>
<p>Michel
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: gorky5</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-292</link>
		<pubDate>Tue, 28 Oct 2008 16:26:47 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-292</guid>
					<description>Hi Michel. I'm trying to do something similar to Mistephen - content rotation based on the day/week/month of the year. I can do it using ssi files, but they don't cooperate well with php pages.

I've uploaded your index.php, content-rotation.php and some dummy index.html pages to my server, but I can't see how it's choosing the specific filenames based on the date command.

Is there a way to specify that it looks for, say, 1.shtml, 2.html and so on, if that number is the day of the year? If so, would you be able to publish the entire code that I'll need? (obviously the 1.html or 1.jpg etc files are up to me to create!)

Many thanks in advance. I've spent hours looking for a solution and am more confused than ever!</description>
		<content:encoded><![CDATA[<p>Hi Michel. I&#8217;m trying to do something similar to Mistephen - content rotation based on the day/week/month of the year. I can do it using ssi files, but they don&#8217;t cooperate well with php pages.</p>
<p>I&#8217;ve uploaded your index.php, content-rotation.php and some dummy index.html pages to my server, but I can&#8217;t see how it&#8217;s choosing the specific filenames based on the date command.</p>
<p>Is there a way to specify that it looks for, say, 1.shtml, 2.html and so on, if that number is the day of the year? If so, would you be able to publish the entire code that I&#8217;ll need? (obviously the 1.html or 1.jpg etc files are up to me to create!)</p>
<p>Many thanks in advance. I&#8217;ve spent hours looking for a solution and am more confused than ever!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: michel</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-291</link>
		<pubDate>Tue, 21 Oct 2008 12:54:59 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-291</guid>
					<description>Hi Stephen,

Yes, this is possible.
The original script is designed to show HTML-snippets in random order.

In order to show one &quot;tip&quot; per day you can use the php-function date()
to get the number of a day in the year: &lt;code&gt;date(&amp;#34;z&amp;#34;)&lt;/code&gt;
So the php-script would look like this:

&lt;code&gt;&amp;#60;?php
$content_rotation_list = array(
 &amp;#34;page1.html&amp;#34;,
 &amp;#34;page2.html&amp;#34;,
 &amp;#34;page3.html&amp;#34;,
 &amp;#34;page4.html&amp;#34;,
 . . .
);
$tip_idx = date(&amp;#34;z&amp;#34;) % count($content_rotation_list);
include( $content_rotation_list[ $tip_idx ] );
?&amp;#62;&lt;/code&gt;

Hope this help.

Michel</description>
		<content:encoded><![CDATA[<p>Hi Stephen,</p>
<p>Yes, this is possible.<br />
The original script is designed to show HTML-snippets in random order.</p>
<p>In order to show one &#8220;tip&#8221; per day you can use the php-function date()<br />
to get the number of a day in the year: <code>date(&quot;z&quot;)</code><br />
So the php-script would look like this:</p>
<p><code>&lt;?php<br />
$content_rotation_list = array(<br />
 &quot;page1.html&quot;,<br />
 &quot;page2.html&quot;,<br />
 &quot;page3.html&quot;,<br />
 &quot;page4.html&quot;,<br />
 . . .<br />
);<br />
$tip_idx = date(&quot;z&quot;) % count($content_rotation_list);<br />
include( $content_rotation_list[ $tip_idx ] );<br />
?&gt;</code></p>
<p>Hope this help.</p>
<p>Michel
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: mistephen</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-286</link>
		<pubDate>Thu, 09 Oct 2008 15:58:16 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-286</guid>
					<description>Michael,

What I am trying to do is a &quot;tip of the day.&quot; As I see it I can do this without a database by calling a php script to pull up the html content (and use seperate html files for each tip,) and (in the same script??) use the sequential array modifications you show above so they don't come up randomly, plus (in the same script??) use time() fuction to rotate the html files daily. I would also like to place this code in its own file and call in from my home page. Is all that possible, or an I going down the wrong road?

Stephen</description>
		<content:encoded><![CDATA[<p>Michael,</p>
<p>What I am trying to do is a &#8220;tip of the day.&#8221; As I see it I can do this without a database by calling a php script to pull up the html content (and use seperate html files for each tip,) and (in the same script??) use the sequential array modifications you show above so they don&#8217;t come up randomly, plus (in the same script??) use time() fuction to rotate the html files daily. I would also like to place this code in its own file and call in from my home page. Is all that possible, or an I going down the wrong road?</p>
<p>Stephen
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: dcarlson007</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-284</link>
		<pubDate>Tue, 02 Sep 2008 00:40:27 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-284</guid>
					<description>Michael,

I'm very interested in your content rotation script - I really need to make it work.

Based on your example, it seems each of my rotating content blocks must be placed on a separate .PHP page - is that correct? If this is true, then it seems logical to assume that I'll have to rotate each of the content blocks into a frame - this is not ideal.

So here's my question: Do I need a to place each content block on a separate page? I just need to accomplish either of two things: 1) either rotate each block each time a visitor revisits or refreshes their browser, or 2) auto-rotate each block on, say, 2-hour intervals.

Are my assumptions correct?

Please advise at your earliest opportunity.

Thanks much.

Doug C.</description>
		<content:encoded><![CDATA[<p>Michael,</p>
<p>I&#8217;m very interested in your content rotation script - I really need to make it work.</p>
<p>Based on your example, it seems each of my rotating content blocks must be placed on a separate .PHP page - is that correct? If this is true, then it seems logical to assume that I&#8217;ll have to rotate each of the content blocks into a frame - this is not ideal.</p>
<p>So here&#8217;s my question: Do I need a to place each content block on a separate page? I just need to accomplish either of two things: 1) either rotate each block each time a visitor revisits or refreshes their browser, or 2) auto-rotate each block on, say, 2-hour intervals.</p>
<p>Are my assumptions correct?</p>
<p>Please advise at your earliest opportunity.</p>
<p>Thanks much.</p>
<p>Doug C.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: michel</title>
		<link>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-269</link>
		<pubDate>Fri, 06 Jun 2008 07:48:09 +0000</pubDate>
		<guid>http://askmichel.icoder.com/2006/10/30/content-rotation/#comment-269</guid>
					<description>Hi Koolajay,

When you use a database with server scripts
you need to &lt;em&gt;select&lt;/em&gt; your content by some criteria.
This absolutely depends on your database structure/data.

You can use system timer to toggle the selection criteria by specified time.
For example, the &lt;code&gt;time()&lt;/code&gt; PHP-function gets current &lt;code&gt;timestamp&lt;/code&gt; &lt;small&gt;(the number of seconds since January 1, 1970)&lt;/small&gt;. So the &lt;code&gt;time() / 3600;&lt;/code&gt; sentence produces the number of hours since January 1, 1970. And &lt;code&gt;time() / 7200;&lt;/code&gt; provides you with a unique number every 2 hours.

Lets suppose you have 17 database records with html-code to rotate them on your page. And each of these records has an ordering number. So the PHP code-snippet below could select a new record every 2 hours:
&lt;div style=&quot;border:1px solid silver;padding:1ex;backgroubd-color:#f9f9f9;&quot;&gt;&lt;code&gt;&amp;#60;?php
. . .
$timeFrame = 2; &lt;span style=&quot;color:gray;&quot;&gt;// 2 hours to rotate&lt;/span&gt;
$numberOfRecords = 17;
$selectNumber = (time() / (3600 * $timeFrame)) % $numberOfRecords +1;
$sqlQuery = &amp;#34;SELECT &lt;em&gt;code&lt;/em&gt; FROM &lt;em&gt;table&lt;/em&gt; WHERE &lt;em&gt;num&lt;/em&gt;=$selectNumber&amp;#34;;
if ($sqlResult = mysql_query($sqlQuery)) {
&amp;#160;if ($rec = mysql_fetch_assoc($sqlResult)) {
&amp;#160;&amp;#160;print $rec[&amp;#34;&lt;em&gt;code&lt;/em&gt;&amp;#34;]
&amp;#160;}
}
. . .
?&amp;#62;&lt;/code&gt;&lt;/div&gt;

Hope this helps.
Michel</description>
		<content:encoded><![CDATA[<p>Hi Koolajay,</p>
<p>When you use a database with server scripts<br />
you need to <em>select</em> your content by some criteria.<br />
This absolutely depends on your database structure/data.</p>
<p>You can use system timer to toggle the selection criteria by specified time.<br />
For example, the <code>time()</code> PHP-function gets current <code>timestamp</code> <small>(the number of seconds since January 1, 1970)</small>. So the <code>time() / 3600;</code> sentence produces the number of hours since January 1, 1970. And <code>time() / 7200;</code> provides you with a unique number every 2 hours.</p>
<p>Lets suppose you have 17 database records with html-code to rotate them on your page. And each of these records has an ordering number. So the PHP code-snippet below could select a new record every 2 hours:</p>
<div style="border:1px solid silver;padding:1ex;backgroubd-color:#f9f9f9;"><code>&lt;?php<br />
. . .<br />
$timeFrame = 2; <span style="color:gray;">// 2 hours to rotate</span><br />
$numberOfRecords = 17;<br />
$selectNumber = (time() / (3600 * $timeFrame)) % $numberOfRecords +1;<br />
$sqlQuery = &quot;SELECT <em>code</em> FROM <em>table</em> WHERE <em>num</em>=$selectNumber&quot;;<br />
if ($sqlResult = mysql_query($sqlQuery)) {<br />
&nbsp;if ($rec = mysql_fetch_assoc($sqlResult)) {<br />
&nbsp;&nbsp;print $rec[&quot;<em>code</em>&quot;]<br />
&nbsp;}<br />
}<br />
. . .<br />
?&gt;</code></div>
<p>Hope this helps.<br />
Michel
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
