Home>Article>Backend Development> Detailed explanation of the steps to query, update and delete user information in the ThinkPHP framework

Detailed explanation of the steps to query, update and delete user information in the ThinkPHP framework

php中世界最好的语言
php中世界最好的语言 Original
2018-05-17 14:36:30 1580browse

This time I will bring you a detailed explanation of the steps for querying, updating and deleting user information in the ThinkPHP framework. What are theprecautionsfor querying, updating and deleting user information in the ThinkPHP framework. The following is a practical case, let's take a look.

The example in this article describes how the ThinkPHP framework implements user information query, update and delete functions. Share it with everyone for your reference, the details are as follows:

One code

1,Configuration file

 false, // 关闭调试模式 'DB_TYPE'=> 'mysql', // 数据库类型 'DB_HOST'=> 'localhost', // 数据库服务器地址 'DB_NAME'=>'db_database30', // 数据库名称 'DB_USER'=>'root', // 数据库用户名 'DB_PWD'=>'root', // 数据库密码 'DB_PORT'=>'3306', // 数据库端口 'DB_PREFIX'=>'think_', // 数据表前缀 ); ?>

2,Entry file

3, Controller file

order('id desc')->limit(10)->select(); $this->assign('select',$select); // 模板变量赋值 $this->display(); // 指定模板页 } public function update(){ $db = M('User'); // 实例化模型类,参数数据表名称,不包含前缀 $select = $db->where('id='.$_GET['id'])->select(); $this->assign('select',$select); // 模板变量赋值 $this->display(update); // 指定模板页 if(isset($_POST['id'])){ $data['user'] = $_POST['user']; // 要修改的数据对象属性赋值 $data['pass'] = md5($_POST['pass']); $data['address'] = $_POST['address']; $result=$db->where('id='.$_POST['id'])->save($data); // 根据条件保存修改的数据 if($result){ $this->redirect('Index/index','', 2,'数据更新成功'); //页面重定向 } } } public function delete(){ $db = M('User'); // 实例化模型类,参数数据表名称,不包含前缀 $result=$db->where('id='.$_GET['id'])->delete(); // 删除id为5的用户数据 if($result){ $this->redirect('Index/index','', 2,'数据删除成功'); //页面重定向 } } } ?>

4, Template file one

    用户信息输出  
用户信息
ID 名称 地址 操作
{$user.id} {$user.user} {$user.address} 更新/删除

5, Template file two

    用户信息输出  
用户信息
名称:
密码:
地址:

Second running results

I believe you have mastered the method after reading the case in this article, and there will be more exciting things Please pay attention to other related articles on php Chinese website!

Recommended reading:

Detailed explanation of the steps to calculate personal income tax in PHP (with code)

PHP move_uploaded_file() function practical case Detailed explanation

The above is the detailed content of Detailed explanation of the steps to query, update and delete user information in the ThinkPHP framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn