There are two tables in the database: Large classification Bigtype table and small classification Smalltype table.
Bigtype in the table: Id,bigname;
Smalltype in the table: Smallid,bigid,smallname;
Train of thought: (mainly according to gourd, according to the official example of the whole) first read a large classification table, to achieve large classification, when the large classification of each selection, the selected large classification ID submitted to the server side, through the ID of the corresponding small classification value, the query value returned, insert the appropriate position (note: Because of the Xajax to the client page inserted JavaScript part is not skilled, here I directly to the small classification of the value of the server in order to output the select list menu, so feel a little strange, not very pure feeling ^_^, but has met my needs, did not continue to tune, If there is an opportunity to be improved in the future)
Contains three file structures:
xajaxserver.php
xajaxcommon.php
chose.php
Code references are as follows:
Code for xajaxcommon.php pages
View Plaincopy to Clipboardprint?
function library file containing Xajax
Require_once ("./xajax/xajax_core/xajax.inc.php");
Create a Xajax Object
$xajax = new Xajax ("xajaxserver.php");
Register a function that you want to call via Xajax, which obtains a small classification by a large category ID.
$xajax->registerfunction ("Getsmalltype");
function library file containing Xajax
Require_once ("./xajax/xajax_core/xajax.inc.php");
Create a Xajax Object
$xajax = new Xajax ("xajaxserver.php");
Register a function that you want to call via Xajax, which obtains a small classification by a large category ID.
$xajax->registerfunction ("Getsmalltype");
Code for xajaxserver.php pages
View Plaincopy to Clipboardprint?
Output Chinese, set GB2312
Define (' xajax_default_char_encoding ', ' GB2312 ');
Include Common Files
Require ("xajaxcommon.php");
A function that queries a small taxonomy by Bigid and returns an XML command through the Xajaxresponse object:
function Getsmalltype ($BigID)
{
$objResponse = new Xajaxresponse ();
/*
* Connect to your database and query for the value of the small category by $bigid, the part of the code skipped
* The result of the small classification is stored in the two-dimensional array $smalltyperesult
*/
Start constructing the Select list menu
$j = 0;
while (!emptyempty ($SmallTypeResult [$j]))
{
$Temp. = "<option value= '". $SmallTypeResult [$j][id]. "' > ".
$SmallTypeResult [$j][smallname]. " </option> ";
$j + +;
}
$str = "<select name= ' smalltype ' id= ' Smalltype ' >
<option value= ' 0 ' >[Select Small classification]</option> ";
$str. = $Temp;
$str. = "</select>";
Display the list menu in a layer with the ID of the request page Mdjingdiv
$objResponse->assign ("Mdjingdiv", "InnerHTML", $str);
return $objResponse;
;
}
The request is processed by Xajax before the program outputs
$xajax->processrequest ();
Output Chinese, set GB2312
Define (' xajax_default_char_encoding ', ' GB2312 ');
Include Common Files
Require ("xajaxcommon.php");
A function that queries a small taxonomy by Bigid and returns an XML command through the Xajaxresponse object:
function Getsmalltype ($BigID)
{
$objResponse = new Xajaxresponse ();
/*
* Connect to your database and query for the value of the small category by $bigid, the part of the code skipped
* The result of the small classification is stored in the two-dimensional array $smalltyperesult
*/
Start constructing the Select list menu
$j = 0;
while (!empty ($SmallTypeResult [$j]))
{
$Temp. = "<option value= '". $SmallTypeResult [$j][id]. "' > ".
$SmallTypeResult [$j][smallname]. " </option> ";
$j + +;
}
$str = "<select name= ' smalltype ' id= ' Smalltype ' >
<option value= ' 0 ' >[Select Small classification]</option> ";
$str. = $Temp;
$str. = "</select>";
Display the list menu in a layer with the ID of the request page Mdjingdiv
$objResponse->assign ("Mdjingdiv", "InnerHTML", $str);
return $objResponse;
;
}
The request is processed by Xajax before the program outputs
$xajax->processrequest ();