Forum Moderators: coopster

Message Too Old, No Replies

PHP output from mySQL to XML

         

ChriZ

7:06 pm on Sep 24, 2007 (gmt 0)

10+ Year Member



given tables (with example):

nav (parent_id is a child of id)
id ¦ parent_id ¦ name
1 ¦ 0 ¦ nav
5 ¦ 1 ¦ sub

text
id ¦ text
5 ¦ temp

resulting xml should look like this:


<xml>
<nav id="1" name="nav">
<subnav id="5" name="sub" >temp</subnav>
</nav>
</xml>

I think you get the idea, so I'm I heading the right way? does the table structure make sense?

Here is what I have sofar:


mysql_connect($DBhost,$DBuser,$DBpass);
@mysql_select_db("$DBName");
$query = "SELECT * FROM nav";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
$xml .= "<item ";
$xml .= "id='".$row[0]."' ";
$xml .= "name='".$row[2]."' ";
$xml .= "/>\n";
}

now as you can see I have no clue on how I would store the data and then format it the right way...

Thanks for the help!

Demaestro

7:51 pm on Sep 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I suggest checking Json out.... many of the largest sites use it to output XML from any amount of things.

It is all pre-written and maintained.

[json.org...]