1.
<?php
require_once '../model/nba.class.php';
$nba = new model_nba();
$id = isset($_POST['id']) ? $_POST['id'] : '';
$city = isset($_POST['city']) ? $_POST['city'] : ''; 仅仅是要取的变量
$username = isset($_POST['username']) ? $_POST['username'] : ''; 仅仅是要取的变量
if($id) {//edit if($id)==if(!empty($id))
$rows = $nba->update($id,$city,$username);
} else {
$rows = $nba->add($city,$username);
}
if ($rows) {
$return = array('code'=>200,'msg'=>'ok'); 200为默认值
echo json_encode($return);
} else {
$return = array('code'=>300,'msg'=>'error');
echo json_encode($return);
}
仅仅是有 增加 修改 没有删除
2.
<?php
/**
* Created by JetBrains PhpStorm.
* User: bbu
* Date: 15/4/26
* Time: AM10:33
* To change this template use File | Settings | File Templates.
*/
require_once "../model/cba.class.php";
$cba = new model_cba();
$id = isset($_REQUEST['id'])?$_REQUEST['id']:''; $_REQUEST 不区分get和post 但是效率不怎么好
$city = isset($_POST['city'])?$_POST['city']:'';
$username = isset($_POST['username'])?$_POST['username']:'';
$action = isset($_GET['action'])?$_GET['action']:'';
//if(!empty($id)) $id不为空
if(empty($id)) $id为空
{
$rows = $cba->add($city,$username);
}elseif($id!='' && $action == 'delete')
{
$rows = $cba->delete($id);
header("location:easy/grid.php");
exit;
//$rows = $cba->update($id,$city,$username);
}else
{
$rows = $cba->update($id,$city,$username);
}
if(!empty($rows))
{
$return = array('code'=>200,'msg'=>'ok');
echo json_encode($return);
}else{
$return = array('code'=>300,'msg'=>'no');
echo json_encode($return);
}
增加 修改 删除 在一个页面