CodeIgniter Forums
[Solved] Delete not working properly as wanted - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: [Solved] Delete not working properly as wanted (/thread-67316.html)



[Solved] Delete not working properly as wanted - wolfgang1983 - 02-09-2017

I have a column called code which stores a unique id when user previews a post.

If code is empty it should not remove the row. But for some reason deletes rows the code column is empty as well.

How can I make sure it only removes rows if code is present and has been there for more than 15min


PHP Code:
public function clear_unconfirmed_post() {
     $this->db->select('code');
     $this->db->from($this->db->dbprefix 'post');
     $query $this->db->get();

     if (!empty($query->row()->code)) {    
            
// The where below is OK
            $this->db->where('date_created < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 15 MINUTE))'NULLFALSE); 
            $this->db->delete($this->db->dbprefix 'post');
     }



I have tried


PHP Code:
public function clear_unconfirmed_post() {
        $this->db->where('code is NOT NULL'NULLFALSE);
        $this->db->where('date_created < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 15 MINUTE))'NULLFALSE);
        $this->db->delete($this->db->dbprefix 'post');




RE: Delete not working properly as wanted - Wouter60 - 02-09-2017

Did you try
PHP Code:
$this->db->where('code >',''); 



RE: Delete not working properly as wanted - wolfgang1983 - 02-10-2017

(02-09-2017, 11:43 PM)Wouter60 Wrote: Did you try
PHP Code:
$this->db->where('code >',''); 

This has worked now using a foreach loop


PHP Code:
public function clear_unconfirmed_post() {
        $this->db->select('*');
        $this->db->from($this->db->dbprefix 'post');
        $query $this->db->get();
        foreach ($query->result_array() as $result) {
            if (!empty($result['code'])) {
                $this->db->where('code'$result['code']);
                 $this->db->where('date_created < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 15 MINUTE))'NULLFALSE);
                $this->db->delete($this->db->dbprefix 'post');
            }
        }