Оптимизация функции прохождения по дереву
Funkzia dlia podscheta kol-va vetok v dereve beret uinu vremeni, kogda mnogo vetok.
DB (ia uprostil) sdelana tak: ID / login / ref
id + login - dannogo pol'zovatelia
ref - pod kem etot pol'zovatel' nahoditsia, esli ne pod kem to ref=0.
funkzia sobstvenoo:
Код:
function total_members($ref) {
if($ref == 0 and !isset($_GET['ref'])) {
$ref = $this->user_id();
} else if($ref == 0 and isset($_GET['ref'])) {
$ref = $_GET['ref'];
}
$query = "SELECT * FROM $this->my_db WHERE `ref` = '".$ref."' AND `activation` = 1";
$result = mysql_query($query) or die(mysql_error());
$i = 0;
while ($rows = mysql_fetch_array($result, MYSQL_BOTH)) {
$i+= $this->total_members($rows['id']);
$i++;
}
return $i;
}
if($ref == 0 and !isset($_GET['ref'])) {
$ref = $this->user_id();
} else if($ref == 0 and isset($_GET['ref'])) {
$ref = $_GET['ref'];
}
$query = "SELECT * FROM $this->my_db WHERE `ref` = '".$ref."' AND `activation` = 1";
$result = mysql_query($query) or die(mysql_error());
$i = 0;
while ($rows = mysql_fetch_array($result, MYSQL_BOTH)) {
$i+= $this->total_members($rows['id']);
$i++;
}
return $i;
}
Kakie misli po optimizatsii?
Vozmozhno stoit dobavit' prosto v DB peremennuu total_members i sohraniat' tam kol-vo pol'zovatelei v dereve?
Problemu nashel i ispravil nash talantlevii sys admin. Proanalizirovav zaprosi k DB, on dobavil v index pole "ref". I vse stalo netat'! :)