【发布时间】:2011-03-14 17:09:37
【问题描述】:
我有一个使用此功能和 ActiveRecord 设置的 CI 模型:
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;
}
我有 99.9% 的把握会运行此查询:
SELECT *, TO_DAYS(closingdate) - TO_DAYS(CURDATE()) AS days
FROM challenges
WHERE closingdate > CURDATE()
ORDER BY days ASC
当我通过 phpMyAdmin 或 Sequel Pro 进行该简单查询时,它会从数据库返回 5 行 - 正如预期的那样。 但是,当我在 challenges 控制器中调用以下代码时: p>
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);
}
...然后在视图文件中像这样调用它...
<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 } ?>
...没有任何输出!
这让我很困惑,因为我非常确定我有一个有效的查询,而且我还有两个其他模型函数 - get_ended_competitions 和 get_voting_competitions - 我正在使用这两个函数美好的。代码肯定没有什么不同。
我做错了什么?! :S
谢谢!
杰克
编辑:没有任何内容写入 CodeIgniter 日志或 PHP 的错误日志。
【问题讨论】:
标签: php mysql activerecord codeigniter