/** * @Author: HTL * @Email: [email protected] * @DateTime: 2016-04-22 11:25:02 * @Description: Get the current category All Subclass ID * @pid: Parent class ID */function get_child_ids ($pid) {return $this->__get_ids ($pid, ' ', ' id ');}/** * @Author: HTL * @Email: [email protected] * @DateTime: 2016-04-22 11:25:02 * @Description: Gets all parent class ID * @id under the current classification: Subclass ID */FUNCT Ion Get_parent_ids ($id) {return $this->__get_ids ($id, ' ', ' pid ');}/** * @Author: HTL * @Email: [email  ;p rotected] * @DateTime: 2016-04-22 11:25:02 * @Description: Gets all parent/child class IDs under Class * @pid: Multiple parent/subclass ID Set, delimited * @childids: Found Child/parent category list * @find_column: Where lookup field [Id|pid:default] */function __get_ids ($pid, $childids, $find _column = ' id ') {if (! $pid | | $pid < ; =0 | | strlen (PID) <=0 | | !in_array ($find _column,array (' id ', ' pid '))) return 0; if (! $childids | | strlen ($childids) <=0) $childids = $pid; $column = ($find _column = = ' id '? "pid": "id"),//ID and PID are mutually exclusive $ids = $this->model->where ("$column in ($pid)")->getfieLD ("$find _column", true); $ids = Implode (",", $ids); Not found, returns the IF ($ids <=0) return that has been found $childids; Added to the collection $childids. = ', '. $ids; Recursive lookup return $this->__get_ids ($ids, $childids, $find _column);} /** * @Author: HTL * @Email: [email protected] * @DateTime: 2016-04-07 09:33:27 * @Description: Default state change */function Is_default () {$id = Intval ($_get[' id ')), $type = Intval ($_get[' status '), if ($id >0) {//cancels default if for all subcategories ($type!=1) {$id = $this->_get_child_ids ($id);} else{$id = $this->_get_parent_ids ($id); } print_r ($id); exit; $rst = $this->model->where ("ID in ($id)")->setfield (' Is_default ', $type); if ($rst) {$ This->success (L ("save_success"), U ("index")); else {$this->error (L (' save_error '));}} else {$this->error (L (' parameter_error '));}}
CREATE TABLE ' thk_material ' ( ' id ' int (one) not NULL auto_increment COMMENT ' self-increment id ', ' pid ' int (one-by-one) NULL DEFAULT ' 0 ' COMMENT ' parent class ID ' );
From for notes (Wiz)
thinkphp Get all sub-categories or parent category IDs