text: Q:
  
  create one xml node from two functions php
  
  Im using the google map api with a database connection, I have a function that output an xml file and the JavaScript reads the coordinates . no problem there.
  Now i want to add another function that prints out the users  that have saved coordinates in the db.
  But my xml file prints out like this.
  <blog title="Ipsum" text="IpsumLorem" lat="31.968599" lng="-99.901810"/>
  <blog username="user1"/>
  
  instead of printing user1 in the first row like this
  <blog title="Ipsum" text="IpsumLorem" lat="31.968599" lng="-99.901810" username="user1" />
  
  this is my two functions
  function fetch_articles() {
      $query = $this->link->query("SELECT * FROM blog ");  
      $query->setFetchMode(PDO::FETCH_ASSOC);
      while($row = $query->fetch()) {  
          $node = $dom->createElement("blog");  
      $newnode = $parnode->appendChild($node);   
      $newnode->setAttribute("title",$row['title']);
      $newnode->setAttribute("text", $row['text']);  
      $newnode->setAttribute("lat", $row['lat']);  
      $newnode->setAttribute("lng", $row['lng']);  
      } 
  }
  
  function fetch_users() {
      $query = $this->link->query("SELECT * FROM user ");  
      $query->setFetchMode(PDO::FETCH_ASSOC);
      while($row = $query->fetch()) {  
          $node = $dom->createElement("blog");  
      $newnode = $parnode->appendChild($node);   
      $newnode->setAttribute("username",$row['username']);
      } 
  }
  
   $area = new Areas();
  $area_info = $area->fetch_articles(); 
  $user_info = $area->fetch_users(); 
  echo $dom->saveXML();
  
  Any ideas ?
  
  A:
  
  The code you have lacks a way of connecting the users with the blog posts. Thus, it's probably easiest to just write a query that fetches both in a single result, then adds that to a DOM node. It could work like this: 
  function fetch_articles_with_username() {
      $query = $this->link->query("SELECT * FROM blog LEFT JOIN user WHERE blog.userid = user.id ");  
      $query->setFetchMode(PDO::FETCH_ASSOC);
      while($row = $query->fetch()) {  
          $node = $dom->createElement("blog");  
          $newnode = $parnode->appendChild($node);   
          $newnode->setAttribute("title",$row['title']);
          $newnode->setAttribute("text", $row['text']);  
          $newnode->setAttribute("lat", $row['lat']);  
          $newnode->setAttribute("lng", $row['lng']);  
          $newnode->setAttribute("username",$row['username']);
      } 
  }
  
  You'd use it like above, just making a single call to fetch_articles_with_username().
  
  