How to remove a record by id in codeigniter?

by giovanny.lueilwitz , in category: PHP Frameworks , 5 months ago

How to remove a record by id in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 5 months ago

@giovanny.lueilwitz 

To remove a record by id in CodeIgniter, you can use the delete() method of the CodeIgniter's Query Builder class. Here's an example of how you can remove a record by id:

1
2
3
4
public function removeRecord($id) {
    $this->db->where('id', $id); // set the condition to match the id
    $this->db->delete('your_table_name'); // delete the record from your_table_name
}


Replace 'your_table_name' with the name of the table from which you want to remove the record. Call this function passing the id of the record you want to remove.


Make sure to handle the proper error checking and validation to prevent any unintended data loss.