views:

55

answers:

2

I have a function written to delete entries from a table called stack. I have written similar function for other tables and it works. For this its not working, but no errors too. How can i find out whts wrong?

Controller entry:

function delete_tag($id)
        {

        $this->Mrestaurant->delete_tag($id);
        echo 'deleted!';    

        }

Model Entry:

function delete_tag($id)
    {
    $this->db->where('id', '$id'); 
    $this->db->delete('stack'); 
    }

Database and all i have preloaded:

$this->load->database();
$this->load->model('Mdb','',TRUE);

Every other db functions are working like adding, updating, deleting other datas etc... I'm confused because there is no error. And I don't know how to find out whats wrong.

Update This worked in model

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

Any idea why?

+4  A: 

From looking at your code, I expect this line needs to be corrected:

$this->db->where('id', $id); 

Notice that there are no single quotes (or any quotes) around $id. Your second example worked, because it is an alternative to your first, except this time you didn't use single quotes by accident.

TNi
A: 

@TNi is right, also you can use this (applicable for both numeric are character string type)

function delete_tag($id)
    {
    $this->db->where('id', "'$id'"); 
    $this->db->delete('stack'); 
    }
Sadat
That's CRAZY! Just remove the accidental hard quotes.
Zack