codeigniter: editing and deleting from database

时间秒杀一切 提交于 2019-12-02 13:08:27

Somewhere in you controller you need to detect the 'delete' action. This might be through a URL or through a form input. I am sure you can do this bit.

For instance, a controller might have its method defined as

public function view($question_id=0, $action='') { 

Then you might have a link on your page that has the action part defined as 'delete'. In you controller you would have an

if ($action == 'delete') {

To delete the chosen question from the database you would use

$this-db-where('question_id', $question_id);
$this->db->limit(1);
$this->db->delete('my_table');

Which is described in detail here: http://www.codeigniter.com/userguide3/database/query_builder.html#deleting-data

To edit the data, you would collect your form input thus:

http://www.codeigniter.com/userguide3/libraries/input.html

And using your error checked input values, post the new data to your database using the query builder (linked to earlier).

Something like

$data = array(
   'name' => $name,
   'description' => $description;
);
$this-db-where('question_id', $question_id);
$this->db->update('mytable', $data);

I hope that helps in some way, or if not, please be more specific in your question.

Good luck with your website,

Best wishes,

Paul

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!