Ivan
Ivan

Reputation: 433

Check and confirm

is it possible to make it 1st check if $id from ekstri_subcat exist/set in DB products and then confirm if not exist just delete? any tips on how to make it?

View

atm confirm is running on button click

<button type="button" 
data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-danger" 
onclick="confirm('{{ text_confirm }}') ? $('#form-filter').submit() : false;">
</button>

Controller

if (isset($this->request->post['selected']) && $this->validateDelete()) {
        foreach ($this->request->post['selected'] as $id) {
            $this->model_catalog_ekstri->delete($id);
        }

Model

public function delete($id) {

    $this->db->query("DELETE FROM `" . DB_PREFIX . "ekstri_subcat` WHERE id = '" . (int)$id . "'");

}

Upvotes: 0

Views: 44

Answers (1)

MRustamzade
MRustamzade

Reputation: 1455

Yes it is possible. you can do it like:

if (isset($this->request->post['selected']) && $this->validateDelete()) {
    foreach ($this->request->post['selected'] as $id) {
        if(!empty($id)){
            $this->model_catalog_ekstri->delete($id);
        }
    }
}

You can check if it is in database, just selecting data with id and if it is not empty then delete. But it is not necessary for deletion. if there is not data with id it will not do anything and will not throw error.

Upvotes: 2

Related Questions