Jump to content

Recommended Posts

Hi there,

 

The following form is part of a page to enter information about periodical events. The frequency of said events can be yearly, monthly or daily.

 

The frequency is defined by $freq which eventually will be POSTed from a preceding page.

 

For a yearly event, however I do not want the "month" or "day" options to appear.

 

The IF conditions below do not seem to be working. I suspect it may be the use of OR, or perhaps I need some ELSEs too.

 

Any pointers appreciated.

 

Cheers.

 

Gary

 


<?php 

// This script makes three pull-down menus

// for an HTML form: months, days, years.

// Make the months array:

$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

// Make the days and years arrays and set frequency

$days = range (1, 31);
$years = range (2001, 2009);
$freq = "yearly";

if ($freq = "daily")

{	
// Make the days pull-down menu:

echo '<select name="day">';
foreach ($days as $value) {
	echo "<option value=\"$value\">$value</option>\n";
	}
	echo '</select>';
}

// Make the months pull-down menu:




if ($freq = "monthly" or "yearly")

{
echo '<select name="month">';
foreach ($months as $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
}


// make the year pull-down menu:

if ($freq = "daily" or "monthly" or "yearly")

{	
echo '<select name="year">';
foreach ($years as $value) {
	echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
}


?>


You need to compare the days which would be a double equal (==) the single equals is for assigning.  You also have to compare $freq to each day...

 

i.e.

 

if ($freq == "daily" OR $freq == "monthly" OR $freq == "yearly")

I've implemented the above suggestion to the code below, however it is still resulting in a dropdown box of day, month and year whatever I set the $freq to. I have tried putting the $freq values in both single and double quotes.

 

Can anyone suggest where I might be going wrong?

 


<?php 

// This script makes three pull-down menus

// for an HTML form: months, days, years.

// Make the months array:

$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

// Make the days and years arrays and set frequency

$days = range (1, 31);
$years = range (2001, 2009);
$freq = "monthly";

if ($freq == "daily")

{	
// Make the days pull-down menu:
echo '<select name="day">';
foreach ($days as $value) {
	echo "<option value=\"$value\">$value</option>\n";
	}
	echo '</select>';
}

// Make the months pull-down menu:




if ($freq == "monthly") OR ($freq == "daily")

{
echo '<select name="month">';
foreach ($months as $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
}


// make the year pull-down menu:

if ($freq == "daily") OR ($freq == "monthly" OR ($freq == "yearly")

{	
echo '<select name="year">';
foreach ($years as $value) {
	echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
}


?>

if ($freq == "monthly") OR ($freq == "daily")

 

should be

 

if (($freq == "monthly") OR ($freq == "daily"))

 

 

 

 

if ($freq == "daily") OR ($freq == "monthly" OR ($freq == "yearly")

 

should be

 

if (($freq == "daily") OR ($freq == "monthly") OR ($freq == "yearly"))

 

 

and I would use || rather than 'or'

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.