abstract:数据表/* * config.php文件代码 */<?php/** * 配置medoo框架 */// 如果你使用php的依赖安装。可以使用以下方法自动载入require __DIR__.'/vendor/autoload.php';//需要引入Medoo类的命名空间Medoouse Medoo\Medoo as Db;//数据库的配置参数$config =
数据表
/*
* config.php文件代码
*/
<?php
/**
* 配置medoo框架
*/
// 如果你使用php的依赖安装。可以使用以下方法自动载入
require __DIR__.'/vendor/autoload.php';
//需要引入Medoo类的命名空间Medoo
use Medoo\Medoo as Db;
//数据库的配置参数
$config = [
// 必填
'database_type' => 'mysql',
'database_name' => 'web',
'server' => '127.0.0.1',
'username' => 'root',
'password' => 'root',
// 可选
'charset' => 'utf8',
'port' => 3306,
];
//实例化Medoo类,创建db对象
$db = new Db($config);
/**
* 配置smarty
*/
require __DIR__.'/vendor/smarty/smarty/libs/Smarty.class.php';
$smarty = new Smarty();
//模板存放目录
$smarty->setTemplateDir(__DIR__.'/temp');
//模板编译目录
$smarty->setCompileDir(__DIR__.'/temp_c');
//模板缓存目录
$smarty->setCacheDir(__DIR__.'/cache');
//模板配置目录
$smarty->setConfigDir(__DIR__);
//模板缓存
$smarty->setCaching(false);
//echo __DIR__.'<br>';
//print_r($smarty->getConfigDir()).'<br>';
//exit();
/*
* demo.php文件代码
*/
<?php
/**
* 小型用户管理系统
*/
require 'config.php';
$func = @$_GET['func'];
$uid = @$_GET['uid'];
//初始化页面,查询所有
function init_show(){
global $db;
// echo '输出'.print_r($config,true).'<br>';
// exit();
$rows = $db->select('money','*');
return $rows;
}
$result = init_show();
//查询操作
if(!empty(trim(@$_POST['search']))){
$search = $_POST['search'];
$result = search($search);
}else{
$result = init_show();
}
function search($search){
global $db;
$rows = $db->select('money','*',['OR'=>['username[~]'=>$search,'user_id'=>$search]]);
// if(!$rows){
// echo '<script>alert("查无此数据!")</script>';
// }
return $rows;
}
//添加操作(假设所填表单符合要求)
if(trim($func) == 'addUser'){
echo delete($uid);
}
function addUser(){
global $db;
$username = trim($_POST['username']);
$balance = trim($_POST['balance']);
$province = trim($_POST['province']);
$age = trim($_POST['age']);
$sex = trim($_POST['sex']);
$create_time = time();
$stmt = $db->insert('money',[$username,$balance,$province,$age,$sex,$create_time]);
if($stmt->rowCount() > 0){
return '<script>alert("添加成功!"); location.href="demo.php"</script>';
}else{
return '添加失败:'.$stmt->errorInfo();
}
}
//更新操作(假设所填表单符合要求)
if(trim($func) == 'updateUser'){
echo delete($uid);
}
function updateUser(){
global $db;
$user_id = trim($_POST['user_id']);
$username = trim($_POST['username']);
$balance = trim($_POST['balance']);
$province = trim($_POST['province']);
$age = trim($_POST['age']);
$sex = trim($_POST['sex']);
$stmt = $db->update('money',[$username,$balance,$province,$age,$sex],['user_id'=>$user_id]);
if($stmt->rowCount() > 0){
return '<script>alert("修改成功!"); location.href="demo.php"</script>';
}else{
return '修改失败:'.$stmt->errorInfo();
}
}
//删除操作
if(trim($func) == 'delete' && !empty(trim($uid))){
echo delete($uid);
}
function delete($uid){
global $db;
$stmt = $db->delete('money',['user_id'=>$uid]);
if($stmt->rowCount() > 0){
return '<script>alert("删除成功!"); location.href="demo.php"</script>';
}else{
return '删除失败:'.$stmt->errorInfo();
}
}
//var_dump($result);
//exit();
$_POST = [];
$smarty->assign('rows', $result);
$smarty->display('demo.html');
?>
/*
* demo.html文件代码
*/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>小型用户管理系统</title>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="0" align="center" width="60%">
<caption><h2>用户信息表</h2></caption>
<tr>
<td colspan="8" style="padding: 10px;">
<form action="demo.php" method="post" style="display: inline-block;">
<input type="text" name="search" placeholder="请输入用户id或姓名">
<input type="submit" name="select" value="查询">
</form>
</td>
</tr>
<tr bgcolor="#90ee90">
<th>ID</th>
<th>姓名</th>
<th>存款</th>
<th>省份</th>
<th>年龄</th>
<th>性别</th>
<th>创建时间</th>
<th>操作</th>
</tr>
{foreach $rows as $row}
<tr>
<td>{$row.user_id}</td>
<td>{$row.username}</td>
<td>{$row.balance}</td>
<td>{$row.province}</td>
<td>{$row.age}</td>
<td>{$row.sex}</td>
<td>{$row.create_time}</td>
<td><a href="demo.php">编辑</a> <a onclick="showMes('delete','{$row.user_id}')" href="#">删除</a></td>
</tr>
{foreachelse}
<tr><td colspan="8"><h3 style="text-align: center;">没有找到数据</h3></td></tr>
{/foreach}
<tr><td colspan="8" style="text-align: right;color: #37ff4b;">增加和更新操作控制器有写,页面上太麻烦没弄!</td></tr>
</table>
<script>
function showMes(func, uid) {
if(window.confirm("确定要删除这条数据吗?")){
location.href = 'demo.php?func=' + func + '&uid=' + uid;
// var str = 'demo.php?func=' + func + '&uid=' + uid;
// alert(str);
}
}
</script>
</body>
</html>
Correcting teacher:查无此人Correction time:2019-03-02 09:20:23
Teacher's summary:完成的不错。就是代码有点乱,弄整洁些。继续加油