To make a Flash effect page, the company needs an infinite hierarchy to display the friends invited by users and their deprecation. This forms an infinite relationship, and there may be an infinite number of deprecations. Flash needs data in JSON format, so it has the following code: (PHP implementation, C #, similar, go to the JSON library by yourself ~~)
The Code is as follows:
// -- Query user deprecation information and return JSON for flash
If (! Empty ($ _ GET ['action']) &! Empty ($ _ GET ['input']) {
// Fixed parameter requests will return information
If ($ _ GET ['action'] = 'getinfo' & $ _ GET ['input'] = 1 ){
// Data entity, an entity class
Class UcInvite {
// --- Display the data used
Public $ fuid; // user ID
Public $ funame; // User Name
Public $ furl; // user space address
// --- Display the data used
Public $ fchilds; // a collection of child classes
}
$ Invitecount = 0; // total quantity, used to record the total offline quantity
// Recursive Implementation Method
Function GetShowTreeInvite ($ uid ){
Global $ _ SGLOBAL, $ invitecount;
// Organize and query SQL statements. fuid indicates the deprecation id, uid indicates the parent id, and fusername indicates the username.
$ Inv_ SQL = "select fuid, fusername from". tname ("invite"). "where uid =". $ uid;
$ Inv_query = $ _ SGLOBAL ['db']-> query ($ inv_ SQL );
// The following table and returned array
$ Index = 0;
$ InviteTree = Array ();
$ Invitezcount = 0; // number of sub-classes
// Add information to the array cyclically
While ($ v = $ _ SGLOBAL ['db']-> fetch_array ($ inv_query )){
$ Ui = new UcInvite ();
$ Ui-> fuid = $ v ['fuid'];
$ Ui-> funame = $ v ['fusername'];
$ Ui-> furl = "/home/space. php? Uid = ". $ v ['fuid'];
// Call yourself to recursively query subclass Information
$ Ui-> fchilds = GetShowTreeInvite ($ v ['fuid']);
// Insert the returned array
$ InviteTree [$ index] = $ ui;
$ Index ++;
$ Invitecount ++;
$ Invitezcount ++;
}
// Record the current number of deprecations
$ InviteTree ['invitezcount'] = $ invitezcount;
// Returns array information
Return $ inviteTree;
}
$ Fuid = empty ($ _ GET ['fuid'])? $ Space [uid]: $ _ GET ['fuid'];
// Query information based on the current user ID and return a set
$ InviteTree = GetShowTreeInvite ($ fuid );
// Record the total number of deprecations
$ InviteTree ['invitecount'] = $ invitecount;
// Introduce the json library. Here Services_JSON is used.
// The built-in JSON function is not used because the server is PHP5.2 or later.
Require_once ('../plugins/JSON. php ');
// Json output
$ Json = new Services_JSON ();
Echo $ json-> encode ($ inviteTree );
Exit;
} Else {
Echo 'request parameter error! ';
Exit;
}
}
// -- Query user deprecation information and return JSON for flash
The preceding Code returns a JSON string, for example:
{'0': {'fuid': '000000', 'funame': 'Guo ziwon ', 'furl':'/home/space. php? Uid = 950 ', 'fchilds': {'invitezcount': 0 }}, 'invitezcount': 1, 'invitecount': 1}
Only one
Next, use JS to parse the following:
The Code is as follows: