我的数据库表结构如下:
wdt date teacherid
1 2011-01-11 1001
2 2011-01-11 1002
3 2011-01-12 1001
4 2011-01-12 1002
现在我要做的是从表中选择teacherid =“1001”的日期字段,然后将结果作为数组返回,如数组(“2011-01-11”,“2011-01-12”)
所以在我的视图文件中,我可以检查数组结果中是否存在特定数据,如下所示:
if (in_array("2011-05-18", $date)) // here the $date would be the array result which -
// I am expecting to get from model via controller
{
echo "Found";
}
我的控制器如下所示:
function index(){
$this->load->model('mod_teacher_workingday');
$data['date']= $this->mod_teacher_workingday->get();
$data['main_content']='view_teacher_workingday';
$this->load->view('includes/template',$data);
}
请您告诉我我的模型应该是什么样子,以便将结果作为数组存储在我的视图文件中,我可以检查该数组中是否存在特定数据?仅供参考,我使用的是Codeigniter .
谢谢 :)
3 回答
应该:
如果找不到该ID的结果,返回的数组将为空 .
你为什么不用mysql查找日期,效率更高 .
如果得到0结果,则表示该组合不存在
帮自己一个忙,下载一个支持数据库的IDE . Netbeans允许您通过JDBC驱动程序连接到数据库 . 您可以在应用程序内即时执行原始查询 . 然后,一旦您确认了查询,只需将其传输到Codeigniter Active记录或您正在使用的任何内容,或者只使用Active records raw query .