嗨,我的数据库中有一个名为news
的表,我想使用querybuilder只获取特定id
的新闻。我写了这段代码,但在视图中没有结果。
$this->db->from("news");
$q=$this->db->get_where('news', array('id' => $idNotizia));
$data['notizie'] =$q->result_array();
如果我打印查询的numrow()方法,我可以看到有一行,但如果我为运行此方法,则没有文本
foreach($notizie as $notizia)
{
echo $notizia["titoloit"];
}
3条答案
按热度按时间gr8qqesn1#
哦这个问题问了这么久,从评论中我可以看出错误其实是
错误编号:1066 0x066非唯一表/别名:'news' SELECT * FROM新闻,新闻WHERE id ='1'文件名:controllers/News.php
错误来自数据库。请查看生成的查询
SELECT * FROM news, news
:有两个"新闻",使数据库混乱。2试着删除第一行。jk9hmnmh2#
这个应该可以。在你粘贴的代码中foreach里面的变量是$notizia,我猜你是指$notizie对吗?
lnvxswe23#
型号
应该将数据传递给视图控制器