php怎么修改数据框架 php修改表单数据

php中如何设置框架集1.用iframe框架php怎么修改数据框架,直接在右边打开链接
2.用javascript 。点击左边链接php怎么修改数据框架,异步加载数据显示在右边
ThinkPHP框架实现数据增删改使用TP框架主要是比较简单一些,之前我们写增删改,代码量相对来说还是比较多的 , 这里利用tp框架写起来是非常简单的 , 大大的减少了代码量
这里我是以数据库的nation表为例的,nation表只有两列 , 一列是code
另一列是name,首先是增加add方法
functinon
add()
{
if(empty($_POST))//首先要判断一下是否有传过来的值
{
//如果没有传过来的值,那么直接显示模板就可以,在view文件夹下的Main文件夹下建一个名为add.html的文件就可以了
$this-show();
}
else
{
//如果有传过来的值 , 需要收集信息添加
$n-D("nation");
$n-create();
if($n-add())
{
//已经添加成功了,需要跳转页面,跳转到一个方法
$this-success("添加成功","add",3);
}
else
{
$this-error("添加失败");
}
}
}
其次是删除的方法 , 删除的方法就比较简单了,只要传过来一个主键值就可以的
function
del($code)
{
$n=D("nation");
$n-delete($code);
}
最后是修改的方法,修改的方法相对来说要麻烦一丢丢,因为在我们打开需要修改的界面
会有一个默认的value值
function
update()
{
$n=D("nation");
$arr=$n-find($_GET["b"])
if(empty($_POST))
{
$this-assign("arr",$arr);
//这样在模板页面的input
code的value值为{$arr.code}
同理input
name的value值为{$arr.name}
$this-show();
}
else
{
$n-create();
if($n-save())
{
$this-success("修改成功","add",3);
}
else
{
$this-error("修改失败")
}
}
}
如何修改php框架TP里面有个目录是默认的模板文件夹,如全站的head或是新闻列表等文件都存放在那里面,你可以通过修改里面的模板文件可以达到修改文档样式的目的,如果是要修改功能模块,则可能需要你对这个框架有个清晰的认识了!
PHP CI框架修改数据的方法CI框架下php怎么修改数据框架的PHP增删改查总结php怎么修改数据框架:
controllers下php怎么修改数据框架的 cquery.php文件
[php] view plain copy
?php
class CQuery extends Controller {
//构造函数
function CQuery() {
parent::Controller();
//$this-load-database();
}
function index() {
//调用model其中train为外层文件夹MQuery为model名称queryList为重命名
$this-load-model('train/MQuery','queryList');
//获得返回的结果集这里确定调用model中的哪个方法
$result = $this-queryList-queryList();
//将结果集赋给res
$this-smarty-assign('res',$result);
//跳转到显示页面
$this-smarty-view('train/vquery.tpl');
}
//进入新增页面
function addPage() {
$this-smarty-view('train/addPage.tpl');
}
//新增
function add() {
//获得前台数据
//用户名
$memberName = $this-input-post('memberName');
//密码
$password = $this-input-post('password');
//真实姓名
$userRealName = $this-input-post('userRealName');
//性别
$sex = $this-input-post('sex');
//出生日期
$bornDay = $this-input-post('bornDay');
//e_mail
$eMail = $this-input-post('eMail');
//密码问题
$question = $this-input-post('question');
//密码答案
$answer = $this-input-post('answer');
//调用model
$this-load-model('train/MQuery','addRecord');
//向model中的addRecord传值
$result = $this-addRecord-addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);
//判断返回的结果,如果返回true,则调用本页的index方法,不要写 $result == false 因为返回的值未必是false 也有可能是""
if ($result) {
$this-index();
} else {
echo "add failed.";
}
}
//删除
function deletePage() {
//获得ID
$deleteID = $this-uri-segment(4);
//调用model
$this-load-model('train/MQuery','delRecord');
//将值传入到model的delRecord方法中
$result = $this-delRecord-delRecord($deleteID);
//判断返回值
if ($result) {
$this-index();
} else {
echo "delect failed.";
}
}
//修改先查询
function changePage() {
$changeID = $this-uri-segment(4);
$this-load-model('train/MQuery','changeRecord');
$result = $this-changeRecord-changeRecord($changeID);
//将结果集赋给res
$this-smarty-assign('res',$result);
//跳转到显示页面
$this-smarty-view('train/changePage.tpl');
}
//修改
function change() {
//获得前台数据
//ID
$ID = $this-input-post('id');
//用户名
$memberName = $this-input-post('memberName');
//密码
$password = $this-input-post('password');
//真实姓名
$userRealName = $this-input-post('userRealName');
//性别
$sex = $this-input-post('sex');
//出生日期
$bornDay = $this-input-post('bornDay');
//e_mail
$eMail = $this-input-post('eMail');
//密码问题
$question = $this-input-post('question');
//密码答案
$answer = $this-input-post('answer');
//调用model
$this-load-model('train/MQuery','change');
//向model中的change传值
$result = $this-change-change($ID,$memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);
//判断返回的结果,如果返回true,则调用本页的index方法,不要写 $result == false 因为返回的值未必是false 也有可能是""
if ($result) {
$this-index();
} else {
echo "change failed.";
}
}
}
models中的 mquery.php 文件
[php] view plain copy
?php
class MQuery extends Model {
//构造函数
function MQuery() {
【php怎么修改数据框架 php修改表单数据】parent::Model();
//连接数据库
$this-load-database();
}
//查询列表
function queryList() {
//防止select出的数据存在乱码问题
//mysql_query("SET NAMES GBK");
//SQL语句
$sql = "SELECT ID,member_name,sex,e_mail FROM user_info_t";
//执行SQL
$rs = $this-db-query($sql);
//将查询结果放入到结果集中
$result = $rs-result();
//关闭数据库
$this-db-close();
//将结果集返回
return $result;
}
//新增
function addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {
//防止select出的数据存在乱码问题
//mysql_query("SET NAMES GBK");
//SQL语句
$sql = "INSERT INTO user_info_t (member_name,password,user_real_name,sex,born_day,e_mail,question,answer) " .
"VALUES ('$memberName','$password','$userRealName','$sex','$bornDay','$eMail','$question','$answer')";
//执行SQL
$result = $this-db-query($sql);
//关闭数据库
$this-db-close();
//返回值
return $result;
}
//删除
function delRecord($deleteID) {
//防止select出的数据存在乱码问题
//mysql_query("SET NAMES GBK");
$sql = "DELETE FROM user_info_t WHERE ID = $deleteID";
$result = $this-db-query($sql);
$this-db-close();
return $result;
}
//修改前查询
function changeRecord($changeID) {
//防止select出的数据存在乱码问题
//mysql_query("SET NAMES GBK");
$sql = "SELECT ID,member_name,password,user_real_name,sex,born_day,e_mail,question,answer FROM user_info_t WHERE ID = $changeID";
//执行SQL
$rs = $this-db-query($sql);
$result = $rs-row();//$result = $rs[0]
//关闭数据库
$this-db-close();
//将结果集返回
return $result;
}
//修改
function change($ID,$memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {
//防止select出的数据存在乱码问题
//mysql_query("SET NAMES GBK");
//SQL语句
$sql = "update user_info_t set member_name = '$memberName',password = '$password', user_real_name = '$userRealName'," .
"sex = '$sex',born_day = '$bornDay',e_mail = '$eMail',question = '$question',answer = '$answer'" .
"where ID = $ID";
//执行SQL
$result = $this-db-query($sql);
//关闭数据库
$this-db-close();
//返回值
return $result;
}
}
views 下的 addPage.tpl文件
[php] view plain copy
html
head
/head
bodyform action="{{site_url url='train/cquery/add'}}" method="post"
table border='1'
tr
td用户名/td
tdinput type="text" class="text" name="memberName" id="memberName"//td
/tr
tr
td密码/td
tdinput type="text" class="text" name="password" id="password"//td
/tr
tr
td真实姓名/td
tdinput type="text" class="text" name="userRealName" id="userRealName"//td
/tr
tr
td性别/td
tdinput type="text" class="text" name="sex" id="sex"//td
/tr
tr
td出生日期/td
tdinput type="text" class="text" name="bornDay" id="bornDay"//td
/tr
tr
tde_mail/td
tdinput type="text" class="text" name="eMail" id="eMail"//td
/tr
tr
td密码问题/td
tdinput type="text" class="text" name="question" id="question"//td
/tr
tr
td密码答案/td
tdinput type="text" class="text" name="answer" id="answer"//td
/tr
/table
table
tr
tdinput type="submit" class="button" name="OK" value="https://www.04ip.com/post/提交" /
/td
/tr
/table/form
/body
/html
关于php怎么修改数据框架和php修改表单数据的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读