敲-PHP與MySQL,JSON,-phpmysqljson
hi
敲代碼~
1、php與mysql
5.4 修改介面
同樣是介面和程式。
介面article.modify.php
require_once('../connect.php');
//讀取舊資訊
$id = $_GET['id'];
$query = mysqli_query($con,"select * from article where id=$id");
$data = mysqli_fetch_assoc($query);
?>
無標題文檔
關鍵點在於php的讀取,以及在html中value的php調用。
修改程式article.modify.handle.php
//和資料庫有關的,無條件寫上這麼一句話
require_once('../connect.php');
//接受修改後的資料(表單傳遞)
$id = $_POST['id'];
$title = $_POST['title'];
$author = $_POST['author'];
$description = $_POST['description'];
$content = $_POST['content'];
$dateline = time();
//寫sql修改語句,並做成功與否的判斷,並跳回修改介面
$updatesql = "update article set title='$title',author='$author',description='$description',content='$content',dateline=$dateline where id=$id";
if(mysqli_query($con,$updatesql)){
echo "";
}else{
echo "";
}
?>
5.5 文章刪除
先做需求的分析:同上面幾個略有區別,刪除文章不需要介面,只需要一個刪除按鈕來掉要就行了。所以只有一個檔案。而關鍵的sql語句只有一句
$delsql="delete from article where id=$id";
aritcle.del.handle.php
require_once('../connect.php');
//讀取id號。不像其他的是有傳遞值的
$id = $_GET['id'];
$deletesql = "delete from article where id=$id";
if(mysql_query($deletesql)){
echo "";
}else{
echo "";
}
?>
5.6 文章管理列表
需求分析:列表顯示出所有的文章,然後後面有兩個按鈕,刪除(連結至上一節的刪除模組)和修改(連結至之前的模組)
所以,只需要一個檔案,顯示模組就好
article.manage.php
require_once('../connect.php');
$sql = "select * from article order by dateline desc";
$query = mysqli_query($con,$sql);
if($query&&mysqli_num_rows($query)){
while($row =mysqli_fetch_assoc($query)){
$data[] = $row;
}
}else{
$data = array();
}
?>
無標題文檔
| 後台管理系統 |
|
發布文章
管理文章 |
| 文章管理列表 |
| 編號 |
標題 |
操作 |
if(!empty($data)){foreach($data as $value){?>
|
|
">刪除 ">修改 |
|
| 著作權 |
5.7 函數總結
mysqli_connect()
mysqli_select_db()
mysqli_query()
mysqli_error()
mysqli_fetch_assoc()
mysqli_num_rows()
六、前台管理介面的開發
6.1 文章列表
article.list.php
require_once('connect.php');
$sql = "select * from article order by dateline desc";
$query = mysqli_query($con,$sql);
if($query&&mysqli_num_rows($query)){
while($row = mysqli_fetch_assoc($query)){
$data[] = $row;
}
}
?>
文章發布系統
php與mysql
if(empty($data)){
echo "當前沒有文章,請管理員在後台添加文章";
}else{
foreach($data as $value){
?>
array (size=2) 0 =>
string
'username' (length=8) 1 =>
string
'age' (length=3)
["username","age"]
a:2:{i:0;s:8:"username";i:1;s:3:"age";}
--常用JSON函數
json_encode()——JSON加密
json_decode()——解密
1.3 JSON執行個體講解
http://www.bkjia.com/PHPjc/1077541.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1077541.htmlTechArticle敲-PHP與MySQL,JSON,-phpmysqljson hi 敲代碼~ 1、php與mysql 5.4 修改介面 同樣是介面和程式。 介面article.modify.php ?php require_once('../connect.php'); //讀取...