????:數(shù)據(jù)表/* * config.php文件代碼 */<?php/** * 配置medoo框架 */// 如果你使用php的依賴(lài)安裝??梢允褂靡韵路椒ㄗ詣?dòng)載入require __DIR__.'/vendor/autoload.php';//需要引入Medoo類(lèi)的命名空間Medoouse Medoo\Medoo as Db;//數(shù)據(jù)庫(kù)的配置參數(shù)$config =
數(shù)據(jù)表
/*
* config.php文件代碼
*/
<?php
/**
* 配置medoo框架
*/
// 如果你使用php的依賴(lài)安裝??梢允褂靡韵路椒ㄗ詣?dòng)載入
require __DIR__.'/vendor/autoload.php';
//需要引入Medoo類(lèi)的命名空間Medoo
use Medoo\Medoo as Db;
//數(shù)據(jù)庫(kù)的配置參數(shù)
$config = [
// 必填
'database_type' => 'mysql',
'database_name' => 'web',
'server' => '127.0.0.1',
'username' => 'root',
'password' => 'root',
// 可選
'charset' => 'utf8',
'port' => 3306,
];
//實(shí)例化Medoo類(lèi),創(chuàng)建db對(duì)象
$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
/**
* 小型用戶(hù)管理系統(tǒng)
*/
require 'config.php';
$func = @$_GET['func'];
$uid = @$_GET['uid'];
//初始化頁(yè)面,查詢(xún)所有
function init_show(){
global $db;
// echo '輸出'.print_r($config,true).'<br>';
// exit();
$rows = $db->select('money','*');
return $rows;
}
$result = init_show();
//查詢(xún)操作
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("查無(wú)此數(shù)據(jù)!")</script>';
// }
return $rows;
}
//添加操作(假設(shè)所填表單符合要求)
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 '添加失?。?#39;.$stmt->errorInfo();
}
}
//更新操作(假設(shè)所填表單符合要求)
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 '修改失?。?#39;.$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 '刪除失?。?#39;.$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>小型用戶(hù)管理系統(tǒng)</title>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="0" align="center" width="60%">
<caption><h2>用戶(hù)信息表</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="請(qǐng)輸入用戶(hù)id或姓名">
<input type="submit" name="select" value="查詢(xún)">
</form>
</td>
</tr>
<tr bgcolor="#90ee90">
<th>ID</th>
<th>姓名</th>
<th>存款</th>
<th>省份</th>
<th>年齡</th>
<th>性別</th>
<th>創(chuàng)建時(shí)間</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;">沒(méi)有找到數(shù)據(jù)</h3></td></tr>
{/foreach}
<tr><td colspan="8" style="text-align: right;color: #37ff4b;">增加和更新操作控制器有寫(xiě),頁(yè)面上太麻煩沒(méi)弄!</td></tr>
</table>
<script>
function showMes(func, uid) {
if(window.confirm("確定要?jiǎng)h除這條數(shù)據(jù)嗎?")){
location.href = 'demo.php?func=' + func + '&uid=' + uid;
// var str = 'demo.php?func=' + func + '&uid=' + uid;
// alert(str);
}
}
</script>
</body>
</html>
?? ???:查無(wú)此人?? ??:2019-03-02 09:20:23
???? ??:完成的不錯(cuò)。就是代碼有點(diǎn)亂,弄整潔些。繼續(xù)加油