Home > Backend Development > PHP Tutorial > ThinkPHP5 development (4) query user list (picture and text)

ThinkPHP5 development (4) query user list (picture and text)

黄舟
Release: 2023-03-06 19:56:01
Original
2264 people have browsed it

Directory structure:

ThinkPHP5 development (4) query user list (picture and text)
Rendering:
ThinkPHP5 development (4) query user list (picture and text)
ThinkPHP5 development (4) query user list (picture and text)
1.sql script

-- 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 */;
Copy after login

2 .WriteController
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(&#39;status&#39;,1)->limit(5)->order(&#39;user_id&#39;,&#39;asc&#39;);
        });        $view = new View;        //设置变量输出
        $view->assign(&#39;list&#39;,$list);        return $view->fetch(&#39;index&#39;);
    }
}
Copy after login

3 .WriteView
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>
Copy after login

General idea:
The front end submits a query request to the controller, the controller queries the data according to the conditions, replaces the variables into the view, and renders and returns...

The above is the detailed content of ThinkPHP5 development (4) query user list (picture and text). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template