如何使用codeigniter删除评论,删除基于post_id的用户? 例如:
我希望用户(admin)post_id(1)
删除评论(tester2)这表我的数据库
<table width="540" height="66" border="1" >
<tr>
<td><div align="center"><strong>post_id</strong></div></td>
<td><div align="center"><strong>id_alat</strong></div></td>
<td><div align="center"><strong>user</strong></div></td>
<td><div align="center"><strong>namaalat</strong></div></td>
<td><div align="center"><strong>commnet</strong></div></td>
<td><div align="center"><strong>input_date</strong></div></td>
</tr>
<tr>
<td><div align="center">1</div></td>
<td><div align="center">001</div></td>
<td><div align="center">admin</div></td>
<td><div align="center">alat1</div></td>
<td><div align="center">tester1</div></td>
<td><div align="center">08/09/2015</div></td>
</tr>
<tr>
<td><div align="center">2</div></td>
<td><div align="center">002</div></td>
<td><div align="center">admin</div></td>
<td><div align="center">alat2</div></td>
<td><div align="center">tester2</div></td>
<td><div align="center">08/09/2015</div></td>
</tr>
</table>
&#13;
答案 0 :(得分:1)
查看,
<table width="540" height="66" border="1" >
<tr>
<td><div align="center"><strong>post_id</strong></div></td>
<td><div align="center"><strong>id_alat</strong></div></td>
<td><div align="center"><strong>user</strong></div></td>
<td><div align="center"><strong>namaalat</strong></div></td>
<td><div align="center"><strong>commnet</strong></div></td>
<td><div align="center"><strong>input_date</strong></div></td>
<td><div align="center"><strong>Action</strong></div></td>
</tr>
<tr>
<td><div align="center">1</div></td>
<td><div align="center">001</div></td>
<td><div align="center">admin</div></td>
<td><div align="center">alat1</div></td>
<td><div align="center">tester1</div></td>
<td><div align="center">08/09/2015</div></td>
<td><div align="center"><a href="controller_name/controller_function?id=1&user=admin"><button>Delete</button></a></div></td>
</tr>
<tr>
<td><div align="center">2</div></td>
<td><div align="center">002</div></td>
<td><div align="center">admin</div></td>
<td><div align="center">alat2</div></td>
<td><div align="center">tester2</div></td>
<td><div align="center">08/09/2015</div></td>
<td><div align="center"><a href="controller_name/controller_function?id=2&user=admin"><button>Delete</button></a></div></td>
</tr>
</table>
在Controller,
public function controller_function(){
$id= $_GET['id'];
$user = $_GET['user'];
if($user == "admin"){
$this->load->model('model_name/model_function');
$data = $this->model_function->delete_comment($id);
if(data == true){
echo "Deleted Successfully";
}
}
}
在模特,
public function delete_comment($id){
$this->db->where('post_id',$id);
$sql = $this->db->delete('Your_Comment_Table_Name');
($sql)? return TRUE : return False;
}
我希望这会对你有所帮助