Home >Backend Development >PHP Tutorial >AJAX for PHP simple table data query example_PHP tutorial

AJAX for PHP simple table data query example_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:58:50899browse

Function introduction: AJAX WebShop 3 has supported PHP development since Beta2. AJAX WebShop integrates the development environment of PHP5, so there is no need to install and configure PHP additionally. This example will implement a simple data query operation of AJAX for PHP. This example is a single Table operations can also implement data query of master-slave tables.

1. Data table description
The example uses the Access database. Of course, you can also use mysql or other types of databases. The database name is: demo.mdb, and the table name is product. The created fields are PRODUCT_ID, PRODUCT_NAME, PRODUCT_PRICE, and PRODUCT_AREA.

2. Implement data query
First start AJAX WebShop 3, select "New Project" in File to create a new project.

Figure 1
Set the projectname and web server in the pop-up New Project dialog box. In this example, set the projectname to: php_example and set the web server to: PHP. If you want to modify the project path, please set the path to be stored in Directory.

Figure 2
After setting up the New Project, open "File" and select "New .PHP Service". In the pop-up dialog box, enter the subdirectory demo and set the "Class Name" to: simple_query ; After selecting "Query Data" in ServiceType and clicking "OK", the wizard will generate the PHP single-table query code according to the default template.

Figure 3
Enter the following database connection and sql code (the demo.mdb file is placed in the current code directory): $c.realpath($_SERVER['PATH_TRANSLATED'])."demo.mdb" ;
$sql = "select * from product";
$sqlcount = "select count(*) from product";


Analyzing the testquery.php code, the main implementation is as follows:
1. Loop the data structure and use addField to fill the fields (columns) to $xmlRequest: //fill metadata fields
>

for ($i=1; $i<=$fields_count; $i++) { $fieldname = odbc_field_name($result_id, $i); $datatype = odbc_field_type($ result_id, $i ); $xmlRequest->addField($fieldname, $datatype); Fill data in a row of corresponding fields:                                                                                            
for ($i=0; $i<$record_count; $i++) {
odbc_fetch_row($result_id); $i<$recNo+$maxRows) {
                                        $xmlRequest-                                                                    $xmlRequest->setValueByIndex($j-1, ​​odbc_result( $result_id, $j));                                                   Rows) break; Set the relevant parameters of paging, $xmlRequest->recNo is the start of recording, $xmlRequest->maxRows is the number of records per page, and the total number of $record_count records is obtained by executing "select count(*) from product": >
Copy code

The code is as follows:

$sqlcount = "select count(*) from product";
$result_id = @odbc_do($connid, $sqlcount);
if($result_id==null)
throw new Exception($sqlcount);
odbc_fetch_row($result_id);
$record_ count = odbc_result($result_id,1);
$xmlRequest ->setRecordCount($record_count);                                                                                                                     ​If($maxRows==-1) $maxRows = $record_count; After the background data access class is established, select "New Page" in "File" to open the "New Page" dialog box and set the page name in "File Name", as in this example "simple. htm" click OK to complete the settings. Not finished)
Original text from http://cn.joyistar.com




http://www.bkjia.com/PHPjc/317508.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/317508.html

TechArticle

Function introduction: AJAXWebShop3 has supported PHP development since Beta2. AJAXWebShop integrates the PHP5 development environment, so no need Additional installation and configuration of PHP, this example will implement a simple AJAXforPHP...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn