首页 > 作文

PHP实现数据库的增删查改功能及完整代码

更新时间:2023-04-06 17:48:54 阅读: 评论:0

本文用到:jquery、tp框架

tp_3.2.2/application/home/controller/stucontroller.class.php

<?php /**  * created by phpstorm.  * ur: root  * date: 2018/4/17  * time: 16:32  */ namespace home\controller; u think\controller; class stucontroller extend济南职业学院单招s controller {  public function stushow(){   $this->display("school/stu");  }  public function getdata(){   $studata = m('stu');   $data['id']='';   $data['name']=i('get.name');   $data['age']=i('get投影仪使用.age');   $data['num']=i('get.num');   $data['address']=i('get.add');   $studata->add($data);   $this->success("正在。。。",u('stu/showdata'));  }  public function showdata()  {   $studata = m('stu');   $data=$studata->lect();   $this->assign('info',$data);   $this->display('school/showdata');  }  public function del(){   $id = i('get.id');   $studata = m('stu');   $bool = $studata->where(['id'=>$id])->delete();   if($bool){    echo 1;   }el{    echo 0;   }  }  public function updata()  {   $id = i('get.id');   $studata = m('stu');   $data = $studata->where(['id'=>$id])->find();   $this->assign('data',$data);   $this->display("school/upshowdata");  }  public function updatadeal()  {   $studata = m('stu');   $id = i('get.id');   $data['name']=i('get.name');   $data['age']=i('get.age');   $data['num']=i('get.num');   $data['address']=i('get.add');   $bool = $studata->where(['id'=>$id])->save($data);   if($bool){    $this->showdata();   }el{    echo 0;   }  } } 

tp_3.2.2/application/home/view/school/showdata.html

<!doctype html> <html lang="en"> <head>  <meta chart="utf-8">  <title>数据展示界面</title> </head> <body id="content"> <center>  <h2>学生信息展示</h2> <table border="1">  <th>编号</th>  <th>姓名</th>  <th>年龄</th>  <th>学号</th>  <th>籍贯</th>  <th>操作</th>  <th>操作</th> <foreach name="info" item="vo" >  <tr>   <td>{$vo['id']}</td>   <td>{$vo['name']}</td>   <td>{$vo['age']}</td>   <td>{$vo['num']}</td>   <td>{$vo['address']}</td>   <td><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" class="del" where="{$vo['id']}">删除</a></td>    <td><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" class="up" where="{$vo['id']}">修改</a></td>  </tr> </foreach> </table> </center> </body> </html> <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script> <script>  $('.del').click(function () {   var where = $(this).attr('where');   $.ajax({    type: "get",    url: "{:u('stu/del')}?id="+where,    success: function(msg){     if(msg==1){      alert('删除成功');      location.href('showdata');     }el {      alert('删除失败');     }    }   });  })  $('.up').click(function () {   var where = $(this).attr('where');   location.href('updata?id='+where);   // $.ajax({   //  type: "get",   //  url: "{:u('stu/updata')}?id="+where,   //  success: function(msg){   //   $('#content').html(msg);   //  }   // });  }) </script> 

tp_3.2.2/application/home/view/school/stu.html

<!doctype html> <html lang="en"> <head>  <meta 老人与海简介chart="utf-8">  <meta name="viewport"    content="width=device-width, ur-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">  <meta http-equiv="x-ua-compatible" content="ie=edge">  <title> 学号注册查询系统 </title> </head> <body> <form action="{:u('stu/getdata')}" method="get">  <br>  名字: <input type="text" name="name">  <br>  年龄: <input type="text" name="age"雾霾吃什么>  <br>  学号:<input type="text" name="num">  <br>  籍贯:<input type="text" name="add">  <br>  <input type="submit" value="提交">  <br> </form> </body> </html> 

tp_3.2.2/application/home/view/school/stu.html

<!doctype html> <html lang="en"> <head>  <meta chart="utf-8">  <meta name="viewport"    content="width=device-width, ur-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">  <meta http-equiv="x-ua-compatible" content="ie=edge">  <title> 学号注册查询系统 </title> </head> <body> <form action="{:u('stu/updatadeal')}" method="get">  <input type="hidden" value="{$data['id']}" name="id">  <br>  名字: <input type="text" name="name" value="{$data['name']}">  <br>  年龄: <input type="text" name="女性体检必做项目age" value="{$data['age']}">  <br>  学号:<input type="text" name="num" value="{$data['num']}">  <br>  籍贯:<input type="text" name="add" value="{$data['address']}">  <br>  <input type="submit" value="提交">  <br> </form> </body> </html> 

执行在浏览器里面输入:http://127.0.0.1:90/tp_3.2.2/index.php/home/stu/stushow

点击删除

修改:

总结

以上所述是www.887551.com给大家介绍的php实现数据库的增删查改功能及完整代码,希望对大家有所帮助

本文发布于:2023-04-06 17:48:50,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/39f0e8bc25b8b4d253e32757f0077b20.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:PHP实现数据库的增删查改功能及完整代码.doc

本文 PDF 下载地址:PHP实现数据库的增删查改功能及完整代码.pdf

下一篇:返回列表
标签:学号   籍贯   年龄   查询系统
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图