Jump to content


Photo

PHP Help Please


  • Please log in to reply
29 replies to this topic

#21 zamiel

zamiel

    Forum Support

  • Administration
  • 8,841 posts

Posted 21 April 2006 - 06:18 PM

Easiest way would be to change $rotation to include the extra "C".

$rotation = "ABCCD";

#22 rob

rob

    68% Member

  • +Alcohol-Customer
  • 130 posts

Posted 24 April 2006 - 05:43 PM

I did that but then it just has the c keep rotating so the next day its bccda when it should be bcdda any help would be much appreciated

#23 zamiel

zamiel

    Forum Support

  • Administration
  • 8,841 posts

Posted 24 April 2006 - 05:59 PM

It might help if you write out the weekly combinations or under what circumstances a character gets repeated.

#24 rob

rob

    68% Member

  • +Alcohol-Customer
  • 130 posts

Posted 24 April 2006 - 07:24 PM

Alright every day the thrid block is repeated.

Week 1
Monday= ABCCD
Tuesday= BCDDA
Wednesday=CDAAB
Thrusday=DABBC
Friday=ABCCD

Week 2
Monday= BCDDA
Tuesday= CDAAB
Wednesday=DABBC
Thrusday=ABCCD
Friday=BCDDA

Week 3
Monday= CDAAB
Tuesday= DABBC
Wednesday=ABCCD
Thrusday=BCDDA
Friday=CDAAB


It continues in this matter until it finally works ABCCD to Monday again

#25 zamiel

zamiel

    Forum Support

  • Administration
  • 8,841 posts

Posted 24 April 2006 - 10:13 PM

You simply just have to comprise the new string from the new rotational order.

Take the first 3 characters of the new rotation (say BCDA, so you'll end up with BCD), add the third character to the string again (ie: in this case D, so you now have BCDD) and then copy the last character to the end (which was A, so you now have BCDDA). The FOR loop simply puts the four characters in the order they need to be. The RETURN statement cuts it up and pieces it together again.

<?

function get_rotation($end) {
$rotation = "ABCD";
for ($i=0; $i<$end; $i++)
$rotation = substr($rotation, 1) . $rotation[0];
return substr($rotation, 0, strlen($rotation)-1) . $rotation[strlen($rotation)-2] . $rotation[strlen($rotation)-1];
}


//Testing loop that will print out 5 weeks. Mondays will both be the same in the 1st and 5th weeks etc.
for ($i=0; $i<25; $i++) {
if ($i % 5 == 0)
echo "<P>Week " . (($i / 5) + 1) . "</P>";
echo get_rotation($i) . "<br>";
}

?>

#26 rob

rob

    68% Member

  • +Alcohol-Customer
  • 130 posts

Posted 25 April 2006 - 07:41 AM

Alright I tried that code that you had posted and it worked well except it displayed all the weeks at once (I think that might be due to poor explaining on my part) I only want one to show at time. So Today is: ABCCD sorta thnig. Thanks for your help sorry this is taking so long

#27 zamiel

zamiel

    Forum Support

  • Administration
  • 8,841 posts

Posted 25 April 2006 - 03:48 PM

QUOTE
//Testing loop that will print out 5 weeks. Mondays will both be the same in the 1st and 5th weeks etc.


The loop was just to test / show how it works. Simply change the start and end of the loop to get what you want. For example:

<?

function get_rotation($end) {
$rotation = "ABCD";
for ($i=0; $i<$end; $i++)
$rotation = substr($rotation, 1) . $rotation[0];
return substr($rotation, 0, strlen($rotation)-1) . $rotation[strlen($rotation)-2] . $rotation[strlen($rotation)-1];
}

$start = date('W', time());

echo "<P>Week " . $start . "</P>";

for ($i=$start; $i<$start+5; $i++) {
echo get_rotation($i) . "<br>";
}

?>

This uses the week number of the year to work out what the rotation should be for that week.

#28 rob

rob

    68% Member

  • +Alcohol-Customer
  • 130 posts

Posted 25 April 2006 - 08:40 PM

That displays all weeks block rotation how do I only display one day?

#29 zamiel

zamiel

    Forum Support

  • Administration
  • 8,841 posts

Posted 25 April 2006 - 10:10 PM

Quite simple, you need two things

1. You need the week number,
2. You need the day number.

Add the two together and pass it to the get_rotation function, like:

<?

function get_rotation($end) {
$rotation = "ABCD";
for ($i=0; $i<$end; $i++)
$rotation = substr($rotation, 1) . $rotation[0];
return substr($rotation, 0, strlen($rotation)-1) . $rotation[strlen($rotation)-2] . $rotation[strlen($rotation)-1];
}

$start = date('W', time()); //Uppercase W gets Week #
$dayNo = date('w', time()); //Lower case W gets Day of Week #

echo "<P>Week " . $start . ", Day: " . $dayNo. "</P>";

echo get_rotation($start + ($dayNo - 1)) . "<br>";

?>

I take one off dayNo as Monday is 1 according to Date Function (we start on Sunday, which has a value of 0) and therefore will make Monday's rotation a day ahead. Taking 1 off it fixes this.

#30 rob

rob

    68% Member

  • +Alcohol-Customer
  • 130 posts

Posted 26 April 2006 - 12:40 PM

Thanks ill let that run for a while and let you know how it works thanks again




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users