create one xml node from two functions php -


im using google map api database connection, have function output xml file , javascript reads coordinates . no problem there.

now want add function prints out users have saved coordinates in db.

but xml file prints out this.

<blog title="ipsum" text="ipsumlorem" lat="31.968599" lng="-99.901810"/> <blog username="user1"/> 

instead of printing user1 in first row this

<blog title="ipsum" text="ipsumlorem" lat="31.968599" lng="-99.901810" username="user1" /> 

this 2 functions

function fetch_articles() {     $query = $this->link->query("select * 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 * 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 ?

the code have lacks way of connecting users blog posts. thus, it's easiest write query fetches both in single result, adds dom node. work this:

function fetch_articles_with_username() {     $query = $this->link->query("select * blog left join user 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 above, making single call fetch_articles_with_username().


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -