source: temp/trunk/html/test/nakatest/test.php @ 1328

Revision 1328, 1.9 KB checked in by naka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3require_once("../../require.php");
4
5sfGetParentsArray("dtb_category","parent_category_id", "category_id", 230);
6sfGetChildrenArray("dtb_category","parent_category_id", "category_id", 6);
7
8/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤é»ÒIDÇÛÎó¤ò¼èÆÀ¤¹¤ë */
9function sfGetChildrenArray($table, $pid_name, $id_name, $id) {
10    $objQuery = new SC_Query();
11    $col = $pid_name . "," . $id_name;
12    $arrData = $objQuery->select($col, $table);
13   
14    $arrPID = array();
15    $arrPID[] = $id;
16    $arrChildren = array();
17    $arrChildren[] = $id;
18   
19    $arrRet = sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID);
20   
21    while(count($arrRet) > 0) {
22        $arrChildren = array_merge($arrChildren, $arrRet);
23        $arrRet = sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet);
24    }
25   
26    return $arrChildren;
27}
28
29/* ¿ÆIDľ²¼¤Î»ÒID¤ò¤¹¤Ù¤Æ¼èÆÀ¤¹¤ë */
30function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) {
31    $arrChildren = array();
32    $max = count($arrData);
33   
34    for($i = 0; $i < $max; $i++) {
35        foreach($arrPID as $val) {
36            if($arrData[$i][$pid_name] == $val) {
37                $arrChildren[] = $arrData[$i][$id_name];
38            }
39        }
40    }
41    return $arrChildren;
42}
43
44
45/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤é¿ÆIDÇÛÎó¤ò¼èÆÀ¤¹¤ë */
46function sfGetParentsArray($table, $pid_name, $id_name, $id) {
47    $objQuery = new SC_Query();
48    $col = $pid_name . "," . $id_name;
49    $arrData = $objQuery->select($col, $table);
50   
51    $arrParents = array();
52    $arrParents[] = $id;
53    $child = $id;
54   
55    $ret = sfGetParentsArraySub($arrData, $pid_name, $id_name, $child);
56   
57    while($ret != "") {
58        $arrParents = array_merge($arrParents, $ret);
59        $ret = sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret);
60    }
61   
62    $arrParents = array_reverse($arrParents);
63   
64    return $arrParents;
65}
66
67/* »ÒID½ê°¤¹¤ë¿ÆID¤ò¼èÆÀ¤¹¤ë */
68function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) {
69    $max = count($arrData);
70    $parent = "";
71    for($i = 0; $i < $max; $i++) {
72        if($arrData[$i][$id_name] == $child) {
73            $parent = $arrData[$i][$pid_name];
74            break;
75        }
76    }
77    return $parent;
78}
79
80
81?>
Note: See TracBrowser for help on using the repository browser.