Where am I going wrong in this function? I'm asking it to pull users that have a reminder date that is this year (which works alone) and if the type is equal to Email or Call (this part isn't working). Thank you!
elseif
($_GET['reminder'] == 'thisyear'
&&(isset($_GET['type'])
&& in_array($_GET['type'], array('Email', 'Call'))))
{
$thisyear = date('Y-m-d开发者_如何学C');
$todotype = $_GET['type'];
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND YEAR(reminder) = YEAR(CURDATE()) AND contacttodo.type = '".$todotype."' ORDER BY contacttodo.reminder ASC";
}
UPDATE: This returns no records and there are several with both 'call' and 'email'
elseif
($_GET['reminder'] == 'thisyear'
&& (isset($_GET['type'])
&& in_array($_GET['type'], array('Email', 'Call'))))
{
$thisyear = date('Y-m-d');
$todotype = $_GET['type'];
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND YEAR(reminder) = YEAR(CURDATE()) AND contacttodo.type = '".$todotype."' ORDER BY contacttodo.reminder ASC";
}
You're missing an operator in between your first and second criterion. Try an &&
or ||
.
elseif ($_GET['reminder'] == 'thisyear'
&& isset($_GET['type'])
&& in_array($_GET['type'], array('Email', 'Call'))
) {
...
}
Update: Fixed parenthesis, cleaned up whitespace.
The code from the question, including the missing opening bracket and the missing operator:
elseif( ($_GET['reminder'] == 'thisyear')
&& isset($_GET['type'])
&& in_array($_GET['type'], array('Email', 'Call')))
{
/* … */
}
The error "unexpected T_BOOLEAN_AND" results from the && after the elseif condition:
elseif($_GET['reminder'] == 'thisyear') /* no statement here */
&& (isset($_GET['type']) /* some weird code, resulting in unexpected T_BOOLEAN_AND */
UPDATE: "This only returns one record with type 'call'"
Maybe your emails haven't the reminder set to 'thisyear'. Try:
elseif( ($_GET['reminder'] == 'thisyear')
|| ( isset($_GET['type']) && in_array($_GET['type'], array('Email', 'Call')) ) )
{
/* … */
}
精彩评论