Php 通过codeIgniter更新mysql数据
删除时,我调用了此函数:Php 通过codeIgniter更新mysql数据,php,database,codeigniter,Php,Database,Codeigniter,删除时,我调用了此函数: function delete_categories($id){ $max_rank = $this->categories_model->get_max_rank(); //for getting max rank $rank = $this->categories_model->get_rank_by_id($id); //for getting the current rank $cat_id=array();
function delete_categories($id){
$max_rank = $this->categories_model->get_max_rank(); //for getting max rank
$rank = $this->categories_model->get_rank_by_id($id); //for getting the current rank
$cat_id=array();
for($i=$rank;$i<=$max_rank;$i++){
$cat_id[] = $this->categories_model->get_id_by_rank($i); //contains the categories id that should be updated
}
foreach($cat_id as $id){//categories to be updated
$rank = $this->categories_model->get_rank_by_id($id);
$data['fld_rank']= $rank-1;
$this->categories_model->update_rank($id,$data);
}
//$this->categories_model->delete_category($id);
}
变量$id和$data在上述函数中具有正确的值,但在检查数据库时,这些值未正确更新。其中一些值已更新,一些值未更新
我的tbl_分类如下:
fld_id fld_name fld_description fld_rank fld_status
1 Cat1 Cat1 4 0
2 Cat2 this is cat2 1 0
4 Cat4 this is cat4 2 0
5 Cat3 this is cat 3 3 0
我检查了FireBug中的值所有值都正确,但是更新完成后fld\u等级没有正确更新,请帮助…在代码中$id表示数组$cat\u id的键。因此使用
foreach($key=>$val的cat_id),其中您的值将位于$valdo$this->db->last_query();要查看生成的查询,以检查查询语句是否没有任何问题。@Sudhir:我按照u所述执行了。所有查询都会执行,但上次执行的查询不会更改数据库中的值……您能告诉我是这样吗?在单独的程序(如heidiSQL或phpmyadmin)中运行您的查询-调试它可能会更容易那里
fld_id fld_name fld_description fld_rank fld_status
1 Cat1 Cat1 4 0
2 Cat2 this is cat2 1 0
4 Cat4 this is cat4 2 0
5 Cat3 this is cat 3 3 0