I checked around to see what exactly affected_rows returns. It's supposed to return > 0 if something was deleted, and 0 if nothing was, correct?
But when I delete a product, it is deleted because it exists via the product id. But when I want to test whether the product in question has been deleted by trying to do this in my model:
function delete_product($id)
{
$tables = array('products', 'attributes');
$this->db->where('p_id', $id);
$this->db->delete($tables);
if ($this->db->affected_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
and returning the value to my controller as such:
public function delete()
{
$id = $this->uri->segment(3);
$this->a_model->delete_product($id);
if($res == FALSE)
{
$this->session->set_flashdata('success_delete', 'Product deleted successfully.');
redirect('admin/index');
}
else
{
$this->session->set_flashdata('error_delete', 'Product not deleted. We gots an issue.');
redirect('admin/index');
}
}
The returned value is always false i.e. 0. But when I check my database to see whether the product was deleted, it is deleted. Could someone point out what I'm doing wrong?