Jump to content

actually a math question


TecBrat

Recommended Posts

If I am understanding this correctly, you have a list of items, and you want to have a way to cycle through each item in the list starting at the 1st item on day 1 until the list is empty and then start over.

For example, if you hav a list of threeitems:

Day 1 - Item 1
Day 2 - Item 2
Day 3 - Item 3
Day 4 - Item 1
Day 5 - Item 2
....

If that is the case, then the (+1) in your formula is not needed. Using the same example:

(5 mod 3) = Item 2

However, if these items are in an array or another 0 based index you would want to subtract 1 to get the correct index number.
[quote]If that is the case, then the (+1) in your formula is not needed. Using the same example:

(5 mod 3) = Item 2

However, if these items are in an array or another 0 based index you would want to subtract 1 to get the correct index number.[/quote]
thank you.

what was messing me up was knowing that I would have a zero every L number of days. Now I realize that I need something like
cycle_postion= (D mod L);
if cycle_position==0 then cycle_position=L;

I understand about array indexes, I just needed the core math before I went any further.
In case anyone is interested, here's the implementation. I decided to use a simple switch/case instead of putting the agents in an array. I could replace the switch with include('agentfile'.$cycle_position.'.php');
[code]<?
$number_of_agents=5;
$daycount=date('z');
$cycle_position= ($daycount % $number_of_agents);
if ($cycle_position==0) {$cycle_position=$number_of_agents;}

switch ($cycle_position){
case 1:
echo("<a href=http://www.agent1.com>Agent 1 </a>");
break;

case 2:
echo("<a href=http://www.agent2.com>Agent 2</a>");
break;

case 3:
echo("<a href=http://www.agent3.com>Agent 3</a>");
break;

case 4:
echo("<a href=http://www.agent4.com>Agent 4</a>");
break;

case 5:
echo("<a href=http://www.agent5.com>Agent 5</a>");
break;

default:
break;
}

?>[/code]
There's a much easier way to do this:
[code]<?php
$number_of_agents=5;
$daycount=date('z');
$cycle_position= ($daycount % $number_of_agents);
if ($cycle_position==0) {$cycle_position=$number_of_agents;}
echo '<a href="http://www.agent' . $cycle_position . '.com">Agent ' . $cycle_position . ' </a>';
?>[/code]

Ken
[quote author=kenrbnsn link=topic=116710.msg475772#msg475772 date=1164826133]
There's a much easier way to do this:
[/quote]
You're right.
That is roughly equivilent to what I said about using an include statement. But the echo() version only works as long as the agent link and agent anchor text are always a numeric progression. (What if agent 2 has a domain of www.agent2isreallycool.com and wants anchor text of "Agent 2 Cool"). In the switch version, you can hard code whatever you want for either of these, or in the include() version you can have numericly progressive filenames and put whatever you want in them.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.