MySQL Forums
Forum List  »  German

Zwei Abfragen zusammenfassen
Posted by: Thilo Habenreich
Date: July 24, 2009 02:21AM

Hallo ich habe eine Tabelle mit einem nestedset, nun möchte ich nach einem INSERT, DELTE oder einfach nur nach dem Verschieben eines Knotens die Levels sämtlicher Elemente anpassen. Hier habe ich folgende Funktion:

function reCalculateDepths(){
$sql = 'SELECT n1.tree_id, COUNT(*) AS level
FROM sitestructure AS n1, sitestructure AS n2
WHERE n1.lft BETWEEN n2.lft AND n2.rgt
GROUP BY n1.lft;';

$res = $this->executeQuery($sql);

while($row=mysql_fetch_assoc($res)){
$sql = 'UPDATE `sitestructure` SET depth = '.$row['level'].' WHERE
tree_id='.$row['tree_id'].';';
$this->executeUnbufferedQuery($sql);
}
}

Je mehr Elemente in der Tabelle sind, umso aufwändiger wird das Ganze weil für jedes Element eine eigene Anfrage gestellt wird. Wie kann ich das Ganze nun am besten zu einer oder Zwei Abfragen zusammenfassen?

Options: ReplyQuote


Subject
Views
Written By
Posted
Zwei Abfragen zusammenfassen
2768
July 24, 2009 02:21AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.