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
https://forums.phpfreaks.com/topic/57660-quick-conditionals-question/
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 {
        ...
       }

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)

Archived

This topic is now archived and is closed to further replies.

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