/*设置文档类型和编码方式*/ header('Content-Type:text/json;charset=utf-8'); /*引入公共方法库*/ // require '/Library/WebServer/Documents/HMS/API/util/common.php'; require 'E:/wamp/www/HMS/API/util/common.php'; /** * @desc 分页获取订单列表内容 * @example http://www.hms.com/HMS/API/action/admin/orders_data.act.php?page=0&rows=10 */ // GET方式获取每页显示的行数 $page_rows = $_GET['rows']; // GET方式获取每页的起始数字 (注意:页码page从0开始计时) $page_start = $_GET['page'] * $page_rows; // 获取记录总数 $rows_total = $_mysqli->db_query("select count(*) as count from orders where o_isDel=0")['count']; // 查询结果按照用户登记时间倒序排序 $sql = "select * from orders where o_isDel=0 order by o_upTime desc limit {$page_start},{$page_rows}"; $res = $_mysqli->db_query_all($sql); // 根据c_id获得c_name,根据p_id获得p_name for ($i = 0; $i < sizeof($res); $i++) { $cId = $res[$i]['c_id']; $pId = $res[$i]['p_id']; $res[$i]['c_name'] = $_mysqli->db_query("SELECT c_name FROM customer WHERE c_id={$cId}")['c_name']; $res[$i]['p_name'] = $_mysqli->db_query("SELECT p_name FROM product WHERE p_id={$pId}")['p_name']; } if (sizeof($res)) { $data = formatJson($res); $pageTotal = intval($rows_total / $page_rows); // 支持分页 echo '{"data":' . $data . ',"pages":' . $pageTotal . '}'; }
<?php /*设置文档类型和编码方式*/ header('Content-Type:text/json;charset=utf-8'); /*引入公共方法库*/ require '/Library/WebServer/Documents/HMS/API/util/common.php'; /** * @desc 分页获取订单列表内容 * @example http://www.hms.com/HMS/API/action/admin/orders_data.act.php?page=0&rows=10 */ // GET方式获取每页显示的行数 $page_rows = $_GET['rows']; // GET方式获取每页的起始数字 (注意:页码page从0开始计时) $page_start = $_GET['page'] * $page_rows; // 获取记录总数 $rows_total = $_mysqli->db_query("select count(*) as count from orders where o_isDel=0")['count']; // 查询结果按照用户登记时间倒序排序 $sql = "select * from orders where o_isDel=0 order by o_upTime desc limit {$page_start},{$page_rows}"; $res = $_mysqli->db_query_all($sql); // 根据c_id获得c_name,根据p_id获得p_name for ($i = 0; $i < sizeof($res); $i++) { $cId = $res[$i]['c_id']; $pId = $res[$i]['p_id']; $res[$i]['c_name'] = $_mysqli->db_query("SELECT c_name FROM customer WHERE c_id={$cId}")['c_name']; $res[$i]['p_name'] = $_mysqli->db_query("SELECT p_name FROM product WHERE p_id={$pId}")['p_name']; } if (sizeof($res)) { echo formatJson($res); }
<?php $app->get("/customers", function () { $sql = "SELECT CustomerID,ContactName,Phone FROM customers"; $stmt = DB::prepare($sql); $stmt->execute(); formatJson($stmt->fetchAll()); }); $app->get("/customer/:id", function ($id) { $data = json_decode(\Slim\Slim::getInstance()->request()->getBody()); if ($data->isUpdate) { $sql = "UPDATE customers SET ContactName=?,Phone=? WHERE CustomerID=?"; $stmt = DB::prepare($sql); $stmt->execute(array($data->ContactName, $data->Phone, $data->CustomerID)); } else { $sql = "INSERT INTO customers (CustomerID,ContactName,Phone) VALUES (?,?,?)"; $stmt = DB::prepare($sql); $stmt->execute(array($data->CustomerID, $data->ContactName, $data->Phone)); } formatJson($data); }); $app->delete("/customer/:id", function ($id) { $sql = "DELETE FROM customers WHERE CustomerID=?"; });
$stmt = DB::prepare($sql); $stmt->execute(); formatJson($stmt->fetchAll()); }); $app->get("/employee/:id", function ($id) { //DATE_FORMAT( `date` , '%d/%c/%Y %H:%i:%s' ) AS `date` $sql = "SELECT EmployeeID,FirstName,LastName,HomePhone,DATE_FORMAT(BirthDate,'%d/%c/%Y') as BirthDate FROM employees WHERE EmployeeID=?"; $stmt = DB::prepare($sql); $stmt->execute(array($id)); formatJson($stmt->fetch()); }); $app->post("/employee/", function () { $data = json_decode(\Slim\Slim::getInstance()->request()->getBody()); if ($data->EmployeeID != 0) { $sql = "UPDATE employees SET FirstName=?,LastName=?,HomePhone=?,BirthDate=? WHERE EmployeeID=?"; $stmt = DB::prepare($sql); $stmt->execute(array($data->FirstName, $data->LastName, $data->HomePhone, DB::dateToMySql($data->BirthDate), $data->EmployeeID)); } else { $sql = "INSERT INTO employees (FirstName,LastName,HomePhone,BirthDate) VALUES (?,?,?,?)"; $stmt = DB::prepare($sql); $stmt->execute(array($data->FirstName, $data->LastName, $data->HomePhone, DB::dateToMySql($data->BirthDate))); $data->EmployeeID = DB::lastInsertId(); } formatJson($data); }); $app->delete("/employee/:id", function ($id) { $sql = "DELETE FROM customers WHERE CustomerID=?"; $stmt = DB::prepare($sql); $stmt->execute(array($id)); formatJson(true); });
<?php /*设置文档类型和编码方式*/ header('Content-Type:text/json;charset=utf-8'); /*引入公共方法库*/ // require '/Library/WebServer/Documents/HMS/API/util/common.php'; require 'E:/wamp/www/HMS/API/util/common.php'; /** * @desc 获取初始化数据(第一页全部留言+3类留言的总数) * @example http://www.hms.com/HMS/API/action/admin/messages_data.act.php?page=0&rows=10 */ // GET方式获取每页显示的行数 $page_rows = $_GET['rows']; // GET方式获取每页的起始数字 (注意:页码page从0开始计时) $page_start = $_GET['page'] * $page_rows; // 分类获取记录 $all = formatJson($_mysqli->db_query_all("SELECT * FROM message WHERE m_isDel=0 ORDER BY m_upTime desc LIMIT {$page_start},{$page_rows}")); $needRead = formatJson($_mysqli->db_query_all("SELECT * FROM message WHERE m_isDel=0 AND m_isRead=0 ORDER BY m_upTime desc LIMIT {$page_start},{$page_rows}")); $hasRead = formatJson($_mysqli->db_query_all("SELECT * FROM message WHERE m_isDel=0 AND m_isRead=1 ORDER BY m_upTime desc LIMIT {$page_start},{$page_rows}")); echo '{' . '"all":' . $all . ',"needRead":' . $needRead . ',"hasRead":' . $hasRead . '}';