PHP Help Please
#1
Posted 18 April 2006 - 10:57 AM
I am making a website for my school and our school has blocks for every class (i.e. a block for one student is math and another P.E.) each day our block rotate backwards ( First Day ABCD, Seoncd Day BCDA Third Day CDAB, Fourth Day DABC) I want our website to display the blocks however the blocks only change on weekdays. Is there anyway I can make it display the blocks by rotating every school day? If not how would i make it so I write out every day in advance.)
Thanks for all your Help
Please ask if you don't undestrand
#2
Posted 18 April 2006 - 02:21 PM
Like abcd - bcda - cdab - dabc - abcd
then abcd -abcd and abcd - abcd?
Can you set it to roll for 5 days by 1 then 2 days by 4?
#3
Posted 18 April 2006 - 04:22 PM
It's easier to help someone if you know what they alreay know
#4
Posted 18 April 2006 - 05:55 PM
#5
Posted 18 April 2006 - 05:59 PM
Might help to post any code you actually have.
#6
Posted 18 April 2006 - 06:56 PM
<?
$rotation = "ABCD";
$end = strlen($start_rotation);
echo $rotation . "<br>";
for ($i=0; $i<$end; $i++) {
$rotation = substr($rotation, 1) . $rotation[0];
echo $rotation . "<br>";
}
?>
If you want to make it change for an extra two days, just change $end to equal 6.
#7
Posted 18 April 2006 - 09:08 PM
<?
$rotation = "ABCD";
$end = strlen($start_rotation);
echo $rotation . "<br>";
for ($i=0; $i<$end; $i++) {
$rotation = substr($rotation, 1) . $rotation[0];
echo $rotation . "<br>";
}
?>
If you want to make it change for an extra two days, just change $end to equal 6.
Alright first of all I don't have any code up second of all i don't know how to pronounce permetation algorithm let alone make one.
I understand some of the stuff up there don't know what
$rotation = substr($rotation, 1) . $rotation[0];
thank you for trying to help but a little more explanation would be much appreciated.
Sorry for my Incompedence
#8
Posted 18 April 2006 - 10:00 PM
Per-me-ta-tion
This simply means given a set of characters or numbers to work out all possible combinations of them.
Simply gets the length of the String variable $start_rotation and stores it in $end. This is needed to know when to terminate the loop below. Ofcourse if you want it to continue awhile longer then you simply change this to $end = value. I could've said $end = 4, but if I change $rotation to "ABCDE" I would then have to change $end to 5 to acommodate. This way I don't need to.
$rotation = substr($rotation, 1) . $rotation[0];
echo $rotation . "<br>";
}
This is a FOR loop. It simply repeats while $i is less than $end. So $i starts at 0, then goes to 1, 2, 3 and exit. $i++ tells i to increment by 1 after each repetition. Iteration is one of the core principles of programming.
Substr simply copies part of a string from a predefined point.
Assume $rotation = "ABCD"
In this case I tell it to start at position 1. The character at position 1 is "B" as strings in PHP start at 0. Not specifying an end in the substr means it starts at position 1 and copies what comes after it. In this case "BCD" so that all that is left to do is to take the character at position 0 and append it to the end of the string. You do this with the "." or concatenation operator. So now we have BCDA. Next time through you will get CDAB and so on.
Does the existing site use PHP?
Can you post a URL of it etc?
#9
Posted 19 April 2006 - 08:44 AM
That is my site link big I know. The blocks that are currently up don't rotate. I'll try your suggestions in a little bit when i have more time.
Thanks
#10
Posted 19 April 2006 - 03:59 PM
Edited by rob, 19 April 2006 - 04:01 PM.
#11
Posted 19 April 2006 - 08:35 PM
define('mon', 0);
define('tue', 1);
define('wed', 2);
define('thu', 3);
define('fri', 4);
define('sat', 5);
define('sun', 6);
function get_rotation($end) {
$rotation = "ABCD";
for ($i=0; $i<$end; $i++)
$rotation = substr($rotation, 1) . $rotation[0];
return $rotation;
}
echo get_rotation(thu);
?>
You can pass the method above a value (mon-sun) or an integer value and it will return the rotation for that day. You don't have to use the define section, its just so you can use mon-sun instead of 0 - 6.
Alternatively you could use the system date and time to return to get the value you are after, like:
echo get_rotation(date("w", time()));
This uses time() to return a time stamp of the server and "w" to return a integer value that represents the day. 0 = Sun, 1 = Mon. You don't need to use the defines then.
Notice that the define will have Mon = 0, Tue = 1, but the second has the start a day earlier. To fix it, just add 1.
#12
Posted 19 April 2006 - 09:06 PM
Just one more little bit How do I make it not display the blocks for holiday's like easter and spring break and stuff (I know ill have to code those in seperatly)
#13
Posted 19 April 2006 - 10:23 PM
#14
Posted 20 April 2006 - 06:34 AM
Per-me-ta-tion
This simply means given a set of characters or numbers to work out all possible combinations of them.
Per-mu-ta-tion
#15
Posted 20 April 2006 - 07:38 AM
Per-me-a-tion?
Per-mu-ta-tion?
#16
Posted 20 April 2006 - 07:45 AM
Hope all is working on the site. I looked in on it and todays schedule shows DABC, I hope it is correct and is working out for you.
#17
Posted 20 April 2006 - 12:26 PM
define('mon', 0);
define('tue', 1);
define('wed', 2);
define('thu', 3);
define('fri', 4);
define('sat', 5);
define('sun', 6);
function get_rotation($end) {
$rotation = "ABCD";
for ($i=0; $i<$end; $i++)
$rotation = substr($rotation, 1) . $rotation[0];
return $rotation;
}
echo get_rotation(thu);
?>
and it didn't change on the next day so im tring the other method right now ill see if it changes tommorow
#18
Posted 20 April 2006 - 03:52 PM
echo get_rotation(date("w", time()));
It uses the server's time and date to do the change over.
The line echo get_rotation(thu) will not automatically roll over.
So you should have something line:
<?
function get_rotation($end) {
$rotation = "ABCD";
for ($i=0; $i<$end; $i++)
$rotation = substr($rotation, 1) . $rotation[0];
return $rotation;
}
echo get_rotation(date("w", time()));
?>
#19
Posted 20 April 2006 - 05:41 PM
#20
Posted 21 April 2006 - 11:11 AM
Thanks
Edited by rob, 21 April 2006 - 12:11 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users