I have this delete function in my model. When you press the delete button, it will subtract the number of total notes from the total notes column in my database. For eg. if you had 200 notes, and you deleted one of them, it will be 199 notes AND the note will be deleted from the database.
My code:
public function entry_delete($pid) {
$uid=$this->session->userdata('uid');
$whereConditions = array('pid' => $pid, 'uid' => $uid);
$this->db->where($whereConditions);
$this->db->delete('dayone_entries');
if ($this->db->affected_rows() == 0) {
$sql_entry = "UPDATE users set total_entry = total_entry - 1 WHERE uid = $uid";
$this->db->query($sql_entry);
return true;
} else {
return false;
}
}
But this doesn't work. I don't know why but when I press the delete button from my view, it will delete it from the database AND subtract -1 from my total_entry table. However, if I comment out the
$this->db->delete('dayone_entries');
It will still subtract 1 from the total_entry.
How do I fix this? Thanks.
affected rows > 0, after the deletion was made, then make the subtraction on the other table. your if condition is inverted, ifaffected rows == 0(no affected rows), then make subtraction, that doesn't make sense - Kevin