These are my two different tables .. 1) seminar
2) workshop
Need to show the nearest event by using the column posted_datetime(timestamp).. how to get only one record which is nearest to current date using codeigiter ?
Maybe try a union with a return limit of 1.
select 1, * from seminar
UNION
select 2, * from workshop
ORDER BY posted_datetime DESC
LIMIT 1
I put the leading 1 and 2 in the first column so you can tell if the returned record is a workshop (1) or seminar (2). This whole thing assumes all the fields names are the same in both tables and the bigger assumption, that my untested sql will actually work. =)
this query will return you upcoming nearest seminar
select * from seminar where posted_datetime < now() order by posted_datetime desc limit 1
In CI
$this->db->where('posted_datetime < now()');
$this->db->order_by('posted_datetime','desc');
$this->db->limit(1);
$this->db->get('seminar');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.