Php–easyui DataGrid Data Fetching method Introduction _php Tutorial

Source: Internet
Author: User
Easyui DataGrid is a DataGrid written in Jquery, it is a front-end Web UI technology, generally people in the production of the DataGrid is more common should be using background PHP and other background language, to directly produce HTML syntax, to display D Atagrid, when you want to operate on the DataGrid, when passing parameters to the backend, the entire page is re-generated.

While the Easyui DataGrid supports two approaches, one is that, above, the backend server displays the HTML as well, which is displayed to the front end. Another is, the use of AJAX to produce, just feed the JSON format data to the front end, the front end received data, in their own analysis of the data using JQuery to refresh the screen of this part of the DataGrid.

Here is the second approach, the use of AJAX technology to do, the advantage is that the data layer--control layer---layer three to operate independently, to achieve my previous multi-level architecture design in the preamble of the spirit, will not be like the old method, the generation of HTML is placed in PHP to produce, resulting PHP developers themselves, but also to the HTML and other front-end technology to understand very deep in order to develop the problem.

In doing so, there is another benefit that your front-end UI can be replaced, but the latter program is not used to drastically modify it. There are many different JavaScript datagrid that support JSON data format, and you can refer to the DataGrid provided by other companies to choose the most suitable one to use.

Introduction to this, then directly read the code, will be more understanding of my above meaning:

First of all, you need to design the HTML UI interface, define which fields to display, the display name of the field, and so on, about this part of the field definition, Easyui DataGrid is also available, using JavaScript to dynamically define, and I am accustomed to use HTML directly defined, so it is not complicated, Behind in the division of labor, it is easier to directly to the WEB artists directly to operate.

This section focuses on the setting of the URL.
datagrid2.php

Copy CodeThe code is as follows:






<title>A little Dragon Easyui the DataGrid</title>








A little dragon easyui DataGrid URL Test















Url= "datagrid2_getdata.php" title= "Load Data" pagination= "true" >
UNum User ID Password Birthday Nickname dbsts





In order to define the background interface for data acquisition
datagrid2_getdata.php
Copy CodeThe code is as follows:
$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);
?>

From the above, it can be seen that this is a very simple data obtained by the action.
At first 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, store two of information,
$result ["Total"] there are several information
$result ["Rows"] to store the actual data array set
Finally, the $result array will be generated by the JSON data format to output, the DataGrid received after the processing, 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.

http://www.bkjia.com/PHPjc/326129.html www.bkjia.com true http://www.bkjia.com/PHPjc/326129.html techarticle Easyui DataGrid is a DataGrid written in Jquery, it is a front-end Web UI technology, generally everyone in the production of the DataGrid is more common should be the use of background PHP and so on ...

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