I am having an issue with a database call within Joomla whereas I am looping though an array to pull all records if there is a matching value LIKE that array value.
Here is my code:
$time = JRequest::getVar('time');
if($time == 'Morning') {
$times = array('07', '08', '09', '10', '11');
}
if($time == 'Afternoon') {
$times = array('12', '13', '14', '15', '16');
}
if($time == 'Evening') {
$times = array('17', '18', '19', '20', '21');
}
if(isset($times)) {
$first = array_shift($times);
$query->where('a.startTime LIKE "%'. $first .'%"');
foreach($times as $tim => $val) {
$query->or('a.startTime LIKE "%'. $val .'%"');
}
}
$query->order('a.weekday,a.startTime ASC');
return $query;
If time equals ‘Morning’ I only want it to return records that have the values that are in the ‘Morning’ array.
I am having an issue with the ‘or’ part of my query. I don’t think the ‘$query->or’ is a valid function?
I want the query to execute “WHERE a.startTime LIKE arrayvalue1 OR LIKE arrayvalue2….etc” but am unsure how to do this using the Joomla database queries.
Thanks
You are forget to add these line in your query at the beginning:
For more details go this link:
JDatabaseQuery