Posted By

antpaw on 02/10/09


Tagged

php xml


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

nerdsane
Olli
dimispaceman
fomigo


recursion function for xml


 / Published in: PHP
 

your database needs id, bezeichner and parent fields

  1. <?php
  2.  
  3. mysql_connect("localhost","root","root") or die (mysql_error());
  4.  
  5. function xmlloop($intParent=0, $intEbene=0){
  6. $space = null;
  7.  
  8. $sql = mysql_query("SELECT * FROM xmltest WHERE parent = ".$intParent);
  9.  
  10. while($query = mysql_fetch_assoc($sql)){
  11.  
  12. for ($i=0;$i<$intEbene;$i++) $space .= ' ';
  13.  
  14. echo $space.'<'.$query["bezeichnung"].' de="'.$query["val"].'">'."\n";
  15.  
  16. $child = mysql_fetch_assoc(mysql_query("SELECT COUNT(id) as anzahl FROM xmltest WHERE parent = ".$query["id"]." GROUP BY id"));
  17.  
  18. if($child["anzahl"]>0){
  19. xmlloop($query["id"], ($intEbene+1));
  20. }
  21.  
  22. echo $space.'</'.$query["bezeichnung"].'>'."\n";
  23.  
  24. }
  25. }
  26.  
  27. xmlloop();
  28. ?>

Report this snippet  

You need to login to post a comment.