How PHP uses Easyui DataGrid to get Data

Source: Internet
Author: User
  1. A little Dragon Easyui the DataGrid
  2. A little dragon easyui DataGrid URL Test

  3. 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

  1. $page = isset ($_post[' page ')? Intval ($_post[' page '): 1;

  2. $rows = isset ($_post[' rows ')? Intval ($_post[' rows ']): 10;
  3. $offset = ($page-1) * $rows;
  4. $result = Array ();

  5. $tablename = "Stuser";

  6. // ...
  7. Require_once (". \db\db_config.php");
  8. Require_once (". \db\db_class.php");

  9. $db = new db ();

  10. $db->connect_db ($_db[' host ', $_db[' username '], $_db[' password '], $_db[' dbname ');
  11. $db->query ("SELECT count (*) as Total from $tablename");
  12. $row = $db->fetch_assoc ();

  13. $result ["total"] = $row ["Total"];

  14. $db->query ("select * from $tablename limit $offset, $rows");

  15. $items = Array ();

  16. while ($row = $db->fetch_assoc ()) {
  17. Array_push ($items, $row);
  18. }
  19. $result ["Rows"] = $items;

  20. echo Json_encode ($result);

  21. ?>

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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.