rec.php
1.56 KB
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
54
55
56
57
58
59
<?php
require_once "database.php";
$dbh=new CDataBase("extrem", "localhost", "extrem", "9gvs7AbI");
$dbh->query("set names cp1251");
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
function viewRubrics($id = 0,$parent_id = 4){ // print $parent_id."<br />";
global $dbh,$rubrics;
$sql = "select a.* from categories a where a.parent_id='$id'";
$res = $dbh->query($sql);
while ($row = $dbh->fetch_array($res)){
echo str_repeat(" ", 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 />";
// if(in_array($row['cid'],getParentIdRubric($parent_id))){viewRubrics($row['cid']);}
viewRubrics($row['cid']);
// if($row['level']==0){$this->viewRubrics($row['id']);}
}
}
function getParentIdRubric($id){
//$ids = array();
global $dbh,$ids;
if(!count($ids))$ids = array();
while($id>0){
$res = $dbh->query("select cid,parent_id from categories where cid='$id'");
$row = $dbh->fetch_array($res);
//if(isset($row['id']))
$ids[] = $row['cid'];
$id = $row['parent_id'];
} //print_r($ids);
// sort($ids);
return $ids;
}
$ID = (isset($_GET['ID'])) ? $_GET['ID'] : 1;
viewRubrics(0,$ID);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Âðåìÿ âûâîäà: $time ñåê.\n";
?>