October 30, 200916 yr comment_46120 As i had to find out, you can only do a limited number of things with if-functions, so here is some very basic switch that allows to make basically infinte different events happen in the same item, and with the same activator: [php]@vc=date('z'); @vd=@vc%7+3; //mod-calculation //echo @vd; <-- used for test purposes, to see if mod and the cases work right //echo"<br>"; switch (@vd) { //switch-operator searches for the right case and does the things you told it to do, in this case just echo case 7: echo "monday";break; // always use 'break;' at the end of the case, else you will get all cases after the right one showing up!! case 8: echo "tuesday"; break; case 9: echo "wednesday"; break; case 3: echo "thursay"; break; case 4: echo "friday"; break; case 5: echo "saturday"; break; case 6: echo "sunday"; break;}[/php] this one is a pretty simple useage to give out the day of the week, but switches can also easily be combined with keys (strings go in between "", like 'case "first-key":', 'case "second key":' etc.), random event-generators, whatever you want it to do^^ switches also offer a default-option, which is obviously not fitting for my little example code, but if no case mathces, which might happen with keys, you simple add [php]default: echo "sorry, you don't have the key";[/php] after the last case (BEFORE '}'!) Edited November 1, 200916 yr by Burns Report
October 30, 200916 yr comment_46129 Nice that it works in MDS in the end as well. You forgot to add the comment about having to reset your "@vd=@vc%7+3" next year with a different number through (I told you so ) Report
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.