Jump to content

Quick Conditionals Question


cavey5

Recommended Posts

I have to populate a select box based on the date, so say between June 15th, 2007 and July 14th, 2007 it would echo

 

<select>

<option value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

</select>

 

and between July 15th, 2007 and August 14th, 2007 it would echo

 

<select>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

</select>

 

etc... what is the proper way to do this? I tried creating a date variable with $date = date(ymd); and then did an if statement like

 

if (($date >= 070516) AND ($date <= 070715))

            {

            echo "...";

            }

elseif  if (($date >= 070716) AND ($date <= 070915))

            {

            echo "...";

            }

else {

        ...

      }

 

 

but it always defaults to the last else... what am I doing wrong?

It has to be a logical error, right?

Link to comment
Share on other sites

you dont need the second if after your elseif so..

 

 

if (($date >= 070516) AND ($date <= 070715))
            {
            echo "...";
            }
elseif (($date >= 070716) AND ($date <= 070915))
            {
            echo "...";
            }
else {
        ...
       }

Link to comment
Share on other sites

Well first what is $date? Your system looks like it is not very strong because your leading 0 is insignificant

 

Also ifs are more in the fashion of

if($param1 = $paramanswer && $parm2 = $parmanswer2)  Join with the operator &&

in your case:

 

 

if ($date >= 070516 && $date <= 070715)

Link to comment
Share on other sites

Got it working, thanks... the logical error was the date(ymd); function which displays a two digit year with a leading zero, which has something do with base 8 and gets all screwy. I made is date(Ymd); which makes it 2007 and it works fine...

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.