0

This doesnt seem to work:

 /// delete emails first
         $this->db->where('DateSent', 'DateSent!=NULL');
        $this->db->delete('Emails');

I guess I need to use a loop. Not sure how to go about doing this. Can anyone help?

Cheers

thejoker
  • 159
  • 1
  • 5
  • 17

3 Answers3

4

If you were to look in the very useful CodeIgniter userguide you'll see the operator should be included as part of the first parameter not second. This should solve it:

$this->db->where('DateSent !=', 'NULL');
$this->db->delete('Emails');
Josh Holloway
  • 1,683
  • 2
  • 13
  • 14
1

Try this:

$this->db->query('
    DELETE FROM `Emails`
    WHERE id NOT IN (
        SELECT id
        FROM (
            SELECT id
            FROM `Emails`
            WHERE `Emails`.`DateSent` = NULL
        ) foo
    );
);

Query taken from SQL query: Delete all records from the table except latest N? then modified

Community
  • 1
  • 1
Sergey Telshevsky
  • 12,077
  • 6
  • 55
  • 78
0

First you need to store the selected values into an array say "$checked"

$checked = implode(',',$checked);     //then it looks array('id1','id2','id3',..);

then you can delete as

$this->db->where("iUserId in",$checked);

$this->db->delete('my_table');

that's it.it works for me.i hope it useful for you.accept if its useful

GautamD31
  • 28,552
  • 10
  • 64
  • 85