The below 2 lines updates the database after a comment is deleted by subtracting -1 from comment_total
. I'm getting an error if comment_total
happens to be 0 since we can't subtract -1 from 0. How can i modify this so it subtracts -1 only if comment_total
is larger then 0, otherwise set it to 0.
$query = $this->EE->db->query("SELECT comment_total FROM exp_channel_titles WHERE entry_id = '$entry_id'");
$this->EE->db->query("UPDATE exp_channel_titles set comment_total = '".($query->row('comment_total') - 1)."' WHERE entry_id = '$entry_id'");