Hi there!
I have a CI Model set up with this function and ActiveRecord:
function get_open_competitions()
{
$this->db->select('*, TO_DAYS(closingdate) - TO_DAYS(CURDATE()) AS days')
->from('challenges')
->where('closingdate >','CURDATE()')
->order_by('days','asc');
$query = $this->db->get();
return $query;
}
I'm 99.9% confident that would run this query:
SELECT *, TO_DAYS(closingdate) - TO_DAYS(CURDATE()) AS days
FROM challenges
WHERE closingdate > CURDATE()
ORDER BY days ASC
When I put that plain query through phpMyAdmin or Sequel Pro, it returns 5 rows - as expected - from the database. However when I call in the challenges
controller the following code:
function index()
{
// Fetch the Open for Entry competitions
$data['open'] = $this->cm->get_open_competitions();
// Fetch the Open for Voting competitions
$data['voting'] = $this->cm->get_voting_competitions();
// Fetch the Ended Competitions
$data['ended'] = $this->cm->get_ended_competitions();
$data['colwide'] = 'challenges/challengeshome';
$this->load->view('templatewide',$data);
}
... And then in the view file call it up like this...
<h2>Open for Entry</h2>
<hr/>
<?php foreach ($open->result() as $row) { ?>
<h3>
<?php echo anchor('challenges/view/'.$row->id, $row->title);?> -
<i>Challenge ends and voting begins in <?php echo $row->days;?> days</i>
</h3>
<h4> <?php echo $row->description;?> </h4>
<?php } ?>
... nothing is output!
This is confusing me, because I'm very certain I've got a valid query, and also I have two other Model functions - get_ended_competitions
and get_voting_competitions
- both of which I'm using alongside this which work fine. The code is definitely no different.
What am I doing wrong?! :S
Thanks!
Jack
Edit: Nothing is written to either the CodeIgniter log, or to PHP's error log.