在编码器中查找数据库中实际删除或未删除的数据的方法


method to find actually data deleted or not in database in codeigniter

嗨,每有任何方法来检查数据是否实际上从数据库中删除或不编码?我有一个方法来删除数据从数据库在我的模型

             $this->db->delete('product', array('category' => $id)); 

和我已经设置flash数据在我的控制器数据库中的数据不会被删除,但会显示flash消息。

我需要显示flash数据只有实际从数据库中删除。

我更喜欢这个

在模型中,例如名为" products "

function deleteProductBy( $id ) {
    $this->db->where( 'category', $id );
    $this->db->delete( 'product' );
    if ( $this->db->affected_rows() == '1' ) {return TRUE;}
    else {return FALSE;}
} 
在控制器

  if( $this->products->deleteProductBy($id) == false ){
   // fail message is sad
} 
else{
   // success message is happy
}

让模型中的delete方法只返回true或false——然后在控制器中你决定如何显示结果。然后,当显示结果的方式发生变化时,模型中的delete方法保持不变。当我在说的时候,我的建议是先检查错误的条件。

试试这个:

if($this->db->delete('product', array('category' => $id))) // This will return TRUE if deleted and return FALSE if it couldn't delete the row.

如果这不起作用,我建议使用这样的东西:

$this->db->delete('product', array('category' => $id));
if ($this->db->affected_rows() > 0) // affected_rows will return you the number of affected rows, so if you delete one it will return 1.
{
     // show flash message
}

删除表中的数据后,为该类别id编写一个select查询。如果count为零,则没有该类别id的记录。否则会有某个id的日期。即未删除

例如,

function deleterecord(){
$this->db->delete('product', array('category' => $id));
//return TRUE or redirect to controller.
}
//after the above executed call the below function.
function findrecord(){
$query = $this->db->get_where('product', array('category' => $id));
if($query -> num_rows() == 0){
$str ="There is no data";
return $str;
}
else{
$str ="There is data";
return $str;
}
}

可以打印函数返回值来查找结果