AJAXforPHP simple table data query instance function introduction: AJAX WebShop 3 has supported PHP development since Beta2. AJAX WebShop integrates the PHP5 development environment, so you do not need to install and configure PHP, in this example, an AJAX for PHP simple data query operation is implemented. In this example, a single table operation can also be used to query data in a master/slave table.
1. Data Table description
The example uses an Access database. of course, you can also use mysql or other types of databases. the database name is demo. mdb: The table name is product. the created fields are PRODUCT_ID, PRODUCT_NAME, PRODUCT_PRICE, and PRODUCT_AREA.
2. Data Query
Start AJAX WebShop 3 and select "New Project" in File to create a New Project.
In the New Project dialog box that appears, set projectname and web server. In this example, set projectname to php_example and web server to PHP. If you want to modify the Project path, set the path to be stored in Directory.
After setting the New Project, open "File" and select "New. PHP Service. in the displayed dialog box, enter the sub-directory demo and set "Class Name" to simple_query. in ServiceType, select "Query Data" and click "OK, the Wizard generates the php single table query code based on the default template.
Enter the following database connection and SQL code (demo. mdb files are stored in the current code directory): $ c. realpath ($ _ SERVER ['path _ TRANSLATED ']). "\ demo. mdb ";
$ SQL = "select * from product ";
$ Sqlcount = "select count (*) from product ";
The main implementation of the testquery. php code is as follows:
1. cyclic data structure: fill the field (column) with addField to $ xmlRequest: // fill metadata fields
The code is as follows:
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 );
}
2. record the cyclic result set, call the Append () and SetValue methods to fill in data with the corresponding fields in each line of xmlrequest: // fill data rows
The code is as follows:
For ($ I = 0; $ I <$ record_count; $ I ++ ){
Odbc_fetch_row ($ result_id );
If ($ I >=$ recNo & $ I <$ recNo + $ maxRows ){
$ XmlRequest-> append ();
For ($ j = 1; $ j <= $ fields_count; $ j ++ ){
$ XmlRequest-> setValueByIndex ($ J-1, odbc_result ($ result_id, $ j ));
}
}
If ($ I >=$ recNo + $ maxRows) break;
}
3. set parameters related to paging. $ xmlRequest-> recNo indicates the start record, and $ xmlRequest-> maxRows indicates the number of records per page (*) from product "get the total number of $ record_count records:
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 );
$ RecNo = $ xmlRequest-> recNo;
$ MaxRows = $ xmlRequest-> maxRows;
If ($ maxRows =-1) $ maxRows = $ record_count;
After the background data category class is created, select "New Page" in "File" to open the "New Page" dialog box and set the Page name in "File namespace". for example, in this example, click "OK" to complete the settings.
Unfinished)
From http://cn.joyistar.com