当前位置:Gxlcms > PHP教程 > 敲-PHP与MySQL,JSON,-phpmysqljson_PHP教程

敲-PHP与MySQL,JSON,-phpmysqljson_PHP教程

时间:2021-07-01 10:21:17 帮助过:4人阅读

敲-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实例讲解

www.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'); //读取...

人气教程排行