目錄結構:
效果圖:
1.sql腳本
-- phpMyAdmin SQL Dump -- version 4.4.15.5 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: 2016-07-12 23:05:40 -- 服务器版本: 5.7.12-log -- PHP Version: 7.0.7 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `thinkphp5` -- -- -------------------------------------------------------- -- -- 表的结构 `think_user` -- CREATE TABLE IF NOT EXISTS `think_user` ( `user_id` int(11) NOT NULL, `user_name` varchar(255) NOT NULL, `user_sex` int(11) DEFAULT NULL, `user_tel` varchar(255) DEFAULT NULL, `user_email` varchar(255) DEFAULT NULL, `user_address` varchar(255) DEFAULT NULL, `user_birth` varchar(255) DEFAULT NULL, `user_jointime` varchar(255) DEFAULT NULL, `user_passwd` varchar(255) DEFAULT NULL, `user_signature` varchar(255) DEFAULT NULL, `user_hobby` varchar(255) DEFAULT NULL, `status` int(11) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4; -- -- 转存表中的数据 `think_user` -- INSERT INTO `think_user` (`user_id`, `user_name`, `user_sex`, `user_tel`, `user_email`, `user_address`, `user_birth`, `user_jointime`, `user_passwd`, `user_signature`, `user_hobby`, `status`) VALUES (1, 'thinkphp', 1, '15700000000', 'emial@email.com', '山东省济南市****路', '1111111', '111111', 'qqq', NULL, NULL, 1), (2, 'pangPython', 1, '15700000000', 'email@emial.com', '山东省济南市', '201607096', NULL, '123456', 'nihao', '上速度速度', 1), (3, 'test', 0, '15722222222', 'pangPython@163.com', '北京中关村', '19931212', '12999922', '21232f297a57a5a743894a0e4a801fc3', '这个人特别懒,什么都没写', '抽烟喝酒烫头', 1), (4, '你是什么鬼', 0, '15888889999', 'admin@haha.com', '美国硅谷', '19801002', '213123', '63a9f0ea7bb98050796b649e85481845', '个性前景', '啪啪啪', 1); -- -- Indexes for dumped tables -- -- -- Indexes for table `think_user` -- ALTER TABLE `think_user` ADD PRIMARY KEY (`user_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `think_user` -- ALTER TABLE `think_user` MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
2 .寫入控制器
user\controller\Members.php
<?phpnamespace app\user\controller;use app\index\model\User;use think\View;class Members{ public function index(){ //查询出用户列表 $list = User::all(function($query){ $query->where('status',1)->limit(5)->order('user_id','asc'); }); $view = new View; //设置变量输出 $view->assign('list',$list); return $view->fetch('index'); } }
3 .寫檢視
user\view \members\index.html
<!DOCTYPE html> <html> <head> <title>成员</title> <style> dl{ text-align:center; border:2px solid #00CC99; margin-top:100px; margin-bottom:100px; margin-right:400px; margin-left:400px; } </style> </head> <body> <dl> <h1>成员</h1> {volist name="list" id="vo"} <dt><h3>{$vo.user_id} 姓名:{$vo.user_name}</h3></dt> {/volist} </dl> </body> </html>
大體思路:
前端提交查詢請求給控制器,控制器中根據條件查詢出數據,變數替換到視圖,並渲染返回…
以上是ThinkPHP5開發(四)查詢使用者清單(圖文)的詳細內容。更多資訊請關注PHP中文網其他相關文章!