Jump to content

IF statement question


ryeman98

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

Ok but...how would the code go, I don't think I'm smart enough to really figure this out...late night :P

 

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.