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

3 Answers 3

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');
Sign up to request clarification or add additional context in comments.

2 Comments

Didn't work: A Database Error Occurred Error Number: Incorrect syntax near '='. DELETE FROM Emails WHERE DateSent !=
Sorry had a typo... I've updated it to include single quotes around the NULL
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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.