Blame view

ns/view.php 1.45 KB
42868d70   andryeyev   Создал GIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  <?php
  
  $table="categories"; // òàáëèöà êàòåãîðèé
  $id_name="cid";     // èìÿ ïîëÿ ïåðâè÷íîãî êëþ÷à
  $field_names = array( // èìåíà ïîëåé òàáëèöû
     'left' => 'cleft',
     'right'=> 'cright',
     'level'=> 'clevel',
  );
  
  require_once "database.php";
  require_once "dbtree.php";
  
  function microtime_float()
  {
      list($usec, $sec) = explode(" ", microtime());
      return ((float)$usec + (float)$sec);
  }
  
  $dbh=new CDataBase("extrem", "localhost", "extrem", "9gvs7AbI");
  $dbh->query("set names cp1251");
  $Tree = new CDBTree($dbh, $table, $id_name, $field_names);
  $ID = (isset($_GET['ID'])) ? $_GET['ID'] : 1;
  
  $time_start = microtime_float();
  
  
  if(!(list($leftId, $rightId, $level) = $Tree->getNodeInfo($ID))){}
  
  
  
  //  $sql = "select a.* from $table a left join $table b on (b.cleft<=$leftId and b.cright >=$rightId and b.clevel=a.clevel-1) where (a.cleft>=b.cleft and a.cright <=b.cright) order by a.cleft asc";
    $sql = "select a.* from $table a order by a.cleft asc";
  
    $res = $dbh->query($sql);
      while ($row = $dbh->fetch_array($res)){
       echo str_repeat("&nbsp;", 6*$row['clevel']);
       switch($row['clevel']){
        case 0 :$size = 10; break;
        case 1 :$size = 6; break;
        case 2 :$size = 4; break;
        default : $size = 2; break;
       }
       echo "<a href='?ID=".$row['cid']."'><font size='".$size."'>";
       echo $row['title'];
       echo "</font></a><br />";
      }
  
  $time_end = microtime_float();
  $time = $time_end - $time_start;
  
  echo "Âðåìÿ âûâîäà: $time ñåê.\n";
  ?>