• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 4年前 (2022-01-22) 15次浏览 已收录 0个评论

这篇文章主要介绍了PHP实现数据库的增删查改功能及完整代码,需要的朋友可以参考下

本文用到:jquery、tp框架

TP_3.2.2/Application/Home/Controller/StuController.class.php

<?php /**  * Created by PhpStorm.  * User: root  * Date: 2018/4/17  * Time: 16:32  */ namespace Home\Controller; use Think\Controller; class StuController extends 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->select();   $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;   }else{    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();   }else{    echo 0;   }  } }

TP_3.2.2/Application/Home/View/school/showdata.html

<!DOCTYPE html> <html lang="en"> <head>  <meta charset="UTF-8">  <title>数据展示界面</title> </head> <body id="content"> <center>  <h2>学生信息展示</h2> <table border="1">  <th>编号</th>  <th>姓名</th>  <th>年龄&lt<i style="color:transparent">本文来源gaodai$ma#com搞$$代**码)网8</i><strong>搞代gaodaima码</strong>;/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');     }else {      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>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP实现数据库的增删查改功能及完整代码php实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址