我的用户列表提供了编辑用户和更新配置文件的链接,因为当点击用户的屏幕名称时,它会进入具有相应用户id的配置文件更新视图:
//url:
localhost/damcombd/admin/userprofile/userupdate/3
表单加载nice,地址栏和鼠标悬停状态栏都显示如上所述的链接但事实上,在控制器中,如果我从用户模型中提取具有此id的东西,它只会转到第一个记录或id 1.,并一直这样做。。尽我所能!
原因可能是什么?也检查了任何硬编码ID。。但事实并非如此。。
//with this one too I create a row and get it back like:
$this->commonmodel->create_and_get($table,$data){
$this->db->insert($table,$data);
$lastid=$this->db->insert_id();
$getback=$this->db->get($table,array('id'=>$lastid))->result_array();
return $getback[0];
但每次第一排都会返回什么。。我不知道上面更新的用户配置文件是否也在胡扯。。是虫子还是什么的。。我一点也不明白。。尽我所能:(:(请做点什么…
这可能是因为:
a) 在你的路线中,你要指定一个id,这需要花费所有的时间:
b) 您的控制器正在获取错误的id
c) 您的模型正在执行错误的查询。
我会做的:检查你在routes applocation/config/routes中是否有一句
$routes['admin/userprofile/userupdate/(:num)'] = 'admin/userprofile/userupdate/$1'
也许你忘记了1之前的$;P.
然后,检查您发送的值,以确定是否是正确的id,在收到POST/GET值后,打印它,并检查这个值是否是预期的值(您正在编辑用户2,所以您得到id 2,依此类推)。
如果值正确,请检查您从数据库中检索的内容。在你的模型中,你可以写:
echo $this->db->last_query();
并检查正在执行的SQL查询。就像我上面写的那样,告诉我们发生了什么:D
我提到的第二个问题在使用时得到了解决
$this->db->get_where($table,array('id'=>$lastid));
//actually for get the above line would have been false syntax..
我想我会的我也会想出下一个。。。
我的第一个问题也解决了。。。实际上就是这样。。稍微描述一下,以便有人能得到帮助。。
//If u use
$obj=$this->db->get($table,array('id'=>$lastid))->result_array(); //here then
// it will actually do a simple get all operation and returning:
return $obj[0] //will obviously return the very first row..try as u might.
//so for querying with id always use:
$this->db->get_where();