-
- A little Dragon Easyui the DataGrid
-
-
-
-
-
A little dragon easyui DataGrid URL Test
-
- Url= "datagrid2_getdata.php" title= "Load Data" pagination= "true" > UNum User ID Password Birthday Nickname dbsts
-
-
Copy Code
In order to define the background interface for data acquisition datagrid2_getdata.php
-
$page = isset ($_post[' page ')? Intval ($_post[' page '): 1;
- $rows = isset ($_post[' rows ')? Intval ($_post[' rows ']): 10;
- $offset = ($page-1) * $rows;
- $result = Array ();
-
$tablename = "Stuser";
- // ...
- Require_once (". \db\db_config.php");
- Require_once (". \db\db_class.php");
-
$db = new db ();
- $db->connect_db ($_db[' host ', $_db[' username '], $_db[' password '], $_db[' dbname ');
- $db->query ("SELECT count (*) as Total from $tablename");
- $row = $db->fetch_assoc ();
-
$result ["total"] = $row ["Total"];
-
$db->query ("select * from $tablename limit $offset, $rows");
-
$items = Array ();
- while ($row = $db->fetch_assoc ()) {
- Array_push ($items, $row);
- }
- $result ["Rows"] = $items;
-
echo Json_encode ($result);
- ?>
Copy Code
From the above, it can be seen that this is a very simple data obtained by the action. At the beginning the DataGrid will pass in two parameters, $_post[' page ') is currently on page $_post[' rows ') to display several pieces of information per page
Then, to use an array $result, hold two pieces of information, $result ["Total"] a few pieces of information $result["rows"] store the actual data array set to be $result array, producing the JSON data format to output, the DataGrid After receiving it will be processed, refresh the screen.
Later, in the further, can be datagrid2_getdata.php in the abstraction of a layer, that belongs to the Easyui DataGrid unique data format processing part of the database access to the portion of the separation, each independent out into two classes to deal with.
A good architecture and class design, in fact, are built on the accumulation of experience, the continuous evolution of the original framework, the most important thing is that each class division of labor to be clear and accurate, this is to cope with the above, the continuous evolution of the problem to do the corresponding measures, This will make it easier to modify and adjust in the future.
Otherwise easier to become, you want to change but do not know where to start, because a change there are dozens of, or even hundreds of programs waiting for you, to be modified together, thus extending, the stability of the problem, that is, we oppose to modify the original system, is because too much to change, less change a branch is not, the problem dozens of together change, Who to test has not changed well, do not call your user to help you test, think, or forget, do not change, anyway, now the system is also good to use.
|