reiniger Posted October 15, 2012 Report Share Posted October 15, 2012 Sveiki. Kaut kā pašam neizdodas rast risinājum. Būtība man nepieciešams iegūt child ja nav, tad tmpid un ja nav norādīts šims ID, tad meklē to parent id turpinot kokam virzoties uz augšu. function getSome($id){ $sql = "SELECT d.* "; $sql .= "FROM obj AS d "; $sql .= "WHERE d.id = {$id} "; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if($row['child'] && $row['tmpid']){ if($row['child']){ echo $row['child']; return $row['child']; }elseif($row['tmpid']) return $row['tmpid']; }else{ getSome($row['parent']); } } Pieļauju ka ir kaut kāda neprecizitāte kas pēc kārtas izpildās. Jo ir tā ka echo man izvada manu nepieciešamo ID, bet return neko neatgriež. Quote Link to comment Share on other sites More sharing options...
reiniger Posted October 15, 2012 Author Report Share Posted October 15, 2012 (edited) Atrisināju pats: function getSome($id){ $sql = "SELECT d.* "; $sql .= "FROM obj AS d "; $sql .= "WHERE d.id = {$id} "; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if($row['child'] || $row['tmpid']){ if($row['child']){ return $row['child']; }elseif($row['tmpid']) return $row['tmpid']; }else{ $ids = getSome($row['parent']); return $ids; } } Edited October 15, 2012 by reiniger Quote Link to comment Share on other sites More sharing options...
larvae Posted October 17, 2012 Report Share Posted October 17, 2012 Tik uzmanīgi ar rekursīviem selektiem - ātri vien visa ātrdarbība podā aizies ;) Quote Link to comment Share on other sites More sharing options...
daGrevis Posted October 17, 2012 Report Share Posted October 17, 2012 Kverijs iekš rekursīvas funckijas ir tas pats kas kverijs iekš kkāda lūpa. Quote Link to comment Share on other sites More sharing options...
v3rb0 Posted October 17, 2012 Report Share Posted October 17, 2012 vismaz pārbaudi, lai argumenti rekursīvam f-jas izsaukumam nav tādi paši kā f-jai. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.