I want to get to start_date
and expire_date
from promotion
from the CodeIgniter database, so that the promotion automatically appears on start_date
and disappears after expire_date
.
How can I achieve this?
This is the database layout:
promotion:
id(primary,autmatic),
image(varchar,255),
description(longtext),
start_date(datetime),
expire_date(datetime),
An example of the content is as follows:
id image description start_date expired_date
1 1.jpg textpromo1 1/10/2015 5/10/2015
2 2.jpg textpromo2 8/10/2015 22/10/2015
2 3.jpg textpromo3 1/11/2015 12/11/2015
And this is my view request code
<?php $query = $this->db->get('promotion'); ?>
<?php foreach($query->result() as $val): ?>
<div class="promotion">
<p><?php echo image; ?></p>
<p><?php echo description; ?></p>
<p><?php echo start_date; ?></p>
<p><?php echo expired_date; ?></p>
</div>
<?php endforeach; ?>
Result:
1.jpg textpromo1 1/10/2015 5/10/2015
2.jpg textpromo2 8/10/2015 22/10/2015
3.jpg textpromo3 1/11/2015 12/11/2015
source
share