Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions conn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$conn = @mysql_connect('127.0.0.1','root','xxxx');
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('db_01', $conn);

?>
31 changes: 31 additions & 0 deletions css/mystyle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
h2,h4
{
color:green;
letter-spacing: 2px;
word-spacing: 10px;
}

h2
{
text-align: center;
text-shadow: 5px 5px 5px #FF0000;
}
table
{
border-collapse:collapse;
}
table,th, td
{
border: 1px solid green;
}

th
{
background-color:green;
color: black
}
td
{
text-align: center;
padding: 15px;
}
31 changes: 31 additions & 0 deletions get_users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
include 'conn.php';

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$firstname = isset($_POST['firstname']) ? mysql_real_escape_string($_POST['firstname']) : '';
$lastname = isset($_POST['lastname']) ? mysql_real_escape_string($_POST['lastname']) : '';

$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'firstname';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';

$offset = ($page-1)*$rows;

$result = array();

$where = "firstname like '%$firstname%' and lastname like '%$lastname%'";

$rs = mysql_query("select count(*) from users where " . $where);
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];

$rs = mysql_query("select * from users where " . $where . " order by $sort $order limit $offset,$rows");

$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;

echo json_encode($result);
?>
86 changes: 86 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="jquery,ui,easy,easyui,web">
<meta name="description" content="easyui help you build your web page easily!">
<title>User CRUD of My Bookstore</title>

<link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/demo/demo.css">

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.net/Public/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="http://www.w3cschool.cc/try/jeasyui/jquery.edatagrid.js"></script>


<script type="text/javascript">
function doSearch(){
$('#dg').datagrid('load',{
firstname: $('#firstname').val(),
lastname: $('#lastname').val()
});
}
$(function(){
$('#dg').edatagrid({
url: 'get_users.php',
saveUrl: 'save_user.php',
updateUrl: 'update_user.php',
destroyUrl: 'remove_user.php'
});
});


</script>

</head>
<body>
<h2>Basic CRUD</h2>
<h4>Search and Double click to edit and Click the header to sort</h4>
<table id="dg"
title="My Users"
class="easyui-datagrid"
style="width:700px;height:300px"
url="get_users.php"
toolbar="#toolbar"
title="My Users"

rownumbers="true"
pagination="true"
fitColumns="true"
singleSelect="true"
>
<thead>
<tr>
<th field="firstname" width="50" sortable="true" editor="{type:'validatebox',options:{required:true}}">First Name</th>
<th field="lastname" width="50" sortable="true" editor="{type:'validatebox',options:{required:true}}">Last Name</th>
<th field="phone" width="50" sortable="true" editor="{type:'text'}">Phone</th>
<th field="email" width="50" sortable="true" editor="{type:'validatebox',options:{validType:'email'}}">Email</th>
</tr>
</thead>
</table>
<div id="toolbar">
<div>
<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#dg').edatagrid('addRow')">New</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:$('#dg').edatagrid('destroyRow')">Destroy</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$('#dg').edatagrid('saveRow')">Save</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#dg').edatagrid('cancelRow')">Cancel</a>
<!--
<a href="#" id="exportjson" class="easyui-linkbutton" style="{background-color: green; padding: 20px;}">Export Json</a>
<a href="#" id="exportcsv" class="easyui-linkbutton" style="{background-color: green; padding: 20px;}">Export CSV</a>
-->
</div>

<div><br/></div>
<div>
<span>First Name:</span>
<input id="firstname" style="line-height:26px;border:1px solid #ccc">
<span>Last Name:</span>
<input id="lastname" style="line-height:26px;border:1px solid #ccc">
<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="doSearch()">Search</a>
</div>
</div>

</body>
</html>
5 changes: 5 additions & 0 deletions readMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
实现功能:CRUD以及,分页,搜索,排序,双击编辑。
前端:jquery-easyui
后端:php交互
数据存储:mysql数据库

14 changes: 14 additions & 0 deletions remove_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$id = intval($_REQUEST['id']);

include 'conn.php';

$sql = "delete from users where id=$id";
$result = @mysql_query($sql);
if ($result){
echo json_encode(array('success'=>true));
} else {
echo json_encode(array('msg'=>'Some errors occured.'));
}
?>
19 changes: 19 additions & 0 deletions save_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];

include 'conn.php';

$sql = "insert into users(firstname,lastname,phone,email) values('$firstname','$lastname','$phone','$email')";
$result = @mysql_query($sql);
echo json_encode(array(
'id' => mysql_insert_id(),
'firstname' => $firstname,
'lastname' => $lastname,
'phone' => $phone,
'email' => $email
));
?>
20 changes: 20 additions & 0 deletions update_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

$id = intval($_REQUEST['id']);
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];

include 'conn.php';

$sql = "update users set firstname='$firstname',lastname='$lastname',phone='$phone',email='$email' where id=$id";
$result = @mysql_query($sql);
echo json_encode(array(
'id' => $id,
'firstname' => $firstname,
'lastname' => $lastname,
'phone' => $phone,
'email' => $email
));
?>