我想删除基于另一个表上的id_comprhensive的问题。
这是我的控制器
**HTML**
<div class="productDivsWrapper">
<div id="" class="productDivs">
<img src="http://placehold.it/290x162">
<h2>This is the DIV title</h2>
<p>Fusce egestas elit eget lorem. Phasellus ullamcorper ipsum rutrum nunc. Praesent ac massa at ligula laoreet iaculis. Vivamus elementum semper nisi.</p>
</div>
...
</div>
**JS**
$('.productDivsWrapper').imagesLoaded( function() {
$(".productDivsWrapper").masonry(
{
itemSelector:'.productDivs',
}
);
});
这是我的模特。
public function delete_question($c){
$this->load->model("admindata");
$this->load->helper('form');
$this->admindata->deletequestion($c);
}
每当我试图运行它时,总是出错。错误是这样的:
致命错误:在第576行的C:\ xampp \ htdocs \ 2016 \ 2016_02_15_Quiz \ application \ models \ admindata.php中调用boolean上的成员函数result()
我的代码出了什么问题?我在admindata.php中有很多查询,但是我在这个函数上遇到了错误。
答案 0 :(得分:1)
您可以尝试以下代码:
function deletequestion($k){
$this->db->from("question");
$this->db->join("main", "main.id_question = question.id_question");
$this->db->where("main.id_comp", $k);
$query = $this->db->delete("question");
return $query;
}
您也可以尝试删除外键检查:
function deletequestion($k){
$hasil = $this->db->query("
SET foreign_key_checks = 0;
DELETE question FROM question JOIN main ON main.id_question = question.id_question
WHERE main.id_comp = $k
SET foreign_key_checks = 1;
");
$query = $hasil->result();
return $query;
}
答案 1 :(得分:1)
您的查询返回true或false,而不是数组,所以只需尝试此
function deletequestion($k){
$hasil = $this->db->query("DELETE question FROM question JOIN main ON main.id_question = question.id_question WHERE main.id_comp = $k");
print_r($hasil);
}
如果它显示1您的查询没问题,如果显示0您的查询未被删除