ryeman98 Posted April 11, 2007 Share Posted April 11, 2007 Hi! I am making a certain kind of website and I want to display different things at different times but I don't want to write a a huge if statement along with a lot of elseif statements. Ex) I want to display something between 2:30PM and 3:00PM. What can I do other than making a ton of elseif statements? Thanks in advance! Rye Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/ Share on other sites More sharing options...
PC Nerd Posted April 11, 2007 Share Posted April 11, 2007 um, try the case switch stuff. i dont really use it my self, but it goes like: $variable_to_test = "string"; case $variable_to_test: switch "string" { echo "this is the string1"; } switch "string2" { echo "this is strng 2"; } else{STUFF} thats should work, but look it up cos i prolly got it wrong gdlk Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226537 Share on other sites More sharing options...
ryeman98 Posted April 11, 2007 Author Share Posted April 11, 2007 Just looking at that...wouldn't I have to put each time in each case...which is kind of like the elseif statements? Just kind of seems like the same thing...Thank you for the idea. Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226540 Share on other sites More sharing options...
PC Nerd Posted April 11, 2007 Share Posted April 11, 2007 i ti different, becauase you not typing ($var == value ){ all the time this way you state the valiable, then simply go switch "value" { its a lot less typing in the end if its long. thats all i can think of Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226543 Share on other sites More sharing options...
PC Nerd Posted April 11, 2007 Share Posted April 11, 2007 another thing, it might work, but have your images or whatever you want to display at the times, in an array, and have to key as the times that you want to display it. then simply get the hour that it is $time = date("H"); and call the array, $Array[$time]; that might work too good luck Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226545 Share on other sites More sharing options...
ryeman98 Posted April 11, 2007 Author Share Posted April 11, 2007 Ok but...how would the code go, I don't think I'm smart enough to really figure this out...late night I have the $date set to the hour and minutes...wouldn't I have to type in every minute? --- It'll be animations that will be displayed...and I will have a schedule for each one to display once in the week...wouldn't that be a lot of arrays? Ok just realizing this now...does this mean that either way I do it, I'll have to do a ton of coding? Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226549 Share on other sites More sharing options...
PC Nerd Posted April 11, 2007 Share Posted April 11, 2007 ok, a) there are a whole heap of images to be displayed on the hour every hour b) these are unique to a day of the week ( ie 24 images a day * 7 days a week) c) it has to be set to that time, and not random? once those are answered you can come up with a solution Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226559 Share on other sites More sharing options...
ryeman98 Posted April 11, 2007 Author Share Posted April 11, 2007 Ok well...heres what I've got to say I guess... a) Yes. There will be many animations to be displayed so I was going to put every animation in a separate file and just use the code 'include' b) I will most likely have each animation display the same time in the AM as it does in the PM just to make it a little less complicated. c) Yes. It must be set to a certain time instead of being random. Will this plan work? Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226564 Share on other sites More sharing options...
PC Nerd Posted April 11, 2007 Share Posted April 11, 2007 ok, put all your animations in a folder, and call them eg "anim01". then you need to determin in what order they go...... i recomend like theyre numbered, 01, 02, 03 etc. if theyre changed every hour............. simply get the date: $time = date("H"); convert to integer ($time = 0 + $time;) then do a math operation to determin which operation, eg. if 0100 hours, then it would be: $image = $time % 100; then call that image: <img src = "directory/anim".$image."> that should be the rough basis of how id do it, good uck have a go and play with that sort of code structure, and post here if you have anyome QQQ Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226566 Share on other sites More sharing options...
ryeman98 Posted April 11, 2007 Author Share Posted April 11, 2007 Alright, that sounds like it'll work great. Thanks! Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226572 Share on other sites More sharing options...
bapi Posted April 11, 2007 Share Posted April 11, 2007 Use "CASE STATEMENT" it will solve u problem easily. Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226583 Share on other sites More sharing options...
ryeman98 Posted April 11, 2007 Author Share Posted April 11, 2007 Case statements are just adding a lot more work. I like the solution that I have, thanks anyway! Link to comment https://forums.phpfreaks.com/topic/46542-if-statement-question/#findComment-226585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.