How to remove a record by id in codeigniter?

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

How to remove a record by id in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 9 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.

Related Threads:

How to remove id from url in laravel?
How to fetch record from database and send it to email using codeigniter?
How to get session id in Codeigniter?
How to send id value in codeigniter?
How to get id after insert in Codeigniter?
How to get/return last inserted id in codeigniter?