php - Unable to delete row in codeigniter

122

I want when thetiming date in CodeIgniter is less than current date then it should delete the row auto. I have a table nameddoctor . The fields areid(int),crated_at(timestamp)timings(varchar),name(varchar).

I use to insert the timing inmm/dd/yyyy format. I want when the date is less than the current date then is should delete the row auto.

MODEL

public function delete_book(){
    $date  = date("m/d/Y");
    $this->db->where("timings < (".$date." - INTERVAL 1 DAY)");
    $this->db->delete("doctors");

}

Please let me know about the fault of my code

414

Answer

Solution:

Use this

$this->db->where("timings < DATE_SUB(curdate(), INTERVAL 1 DAY)",NULL,FALSE);
$this->db->delete("doctors");
972

Answer

Solution:

You should useNOW() function of MySql.NOW() returns the date of the system and it is also compatible with MySql query.

public function delete_book(){
    //$date  = date("m/d/Y");
    $this->db->where("timings < (NOW() - INTERVAL 1 DAY)");
    $this->db->delete("doctors");

}
474

Answer

Solution:

Will work may use

$this->db->where('timings BETWEEN NOW() - INTERVAL 1 DAY AND NOW()', "", false);
$this->db->delete("doctors");

Hope fully works.

412

Answer

Solution:

You may use DATE_SUB function

public function delete_book(){
    $this->db->where("timings < DATE_SUB(curdate(), INTERVAL 1 DAY)");
    $this->db->delete("doctors");

}

above function produced query is :-

DELETE FROM `doctors` WHERE `timings` < DATE_SUB(curdate(), INTERVAL 1 DAY)

People are also looking for solutions to the problem: How to fix this `Illegal string offset` error in php?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.