title: Exporting data from mysql in the xml using php
body: <p>i am trying to export the data from mysql db into a specific xml format, using php.</p>
  
  <p>i have created like this.</p>
  
  <p>if i do like this, i get proper output of a $string in xml.</p>
  
  <pre><code>&lt;?php
  $string = &lt;&lt;&lt;_XML_
  &lt;videos&gt;
  &lt;updated&gt;2010-07-20T00:00:00Z&lt;/updated&gt;
  &lt;video&gt;
    &lt;id&gt;id&lt;/id&gt;
    &lt;title&gt;title&lt;/title&gt;
    &lt;description&gt;description&lt;/description&gt;
    &lt;tags&gt;Comma,Separated,Keywords,Go,Here&lt;/tags&gt;
    &lt;paysite&gt;Name Of site&lt;/paysite&gt;
    &lt;clip_url&gt;http://www.domain.com/path/to/videos/&lt;/clip_url&gt;
    &lt;screen_url&gt;http://www.domain.com/path/to/thumbnails/&lt;/screen_url&gt;
    &lt;clips&gt;
    &lt;clip&gt;
    &lt;duration&gt;20&lt;/duration&gt;
    &lt;width&gt;640&lt;/width&gt;
    &lt;height&gt;480&lt;/height&gt;
    &lt;flv&gt;marta_123.flv&lt;/flv&gt;
    &lt;screens&gt;
    &lt;screen&gt;marta.jpg&lt;/screen&gt;
    &lt;/screens&gt;
    &lt;/clip&gt;
    &lt;clip&gt;
    &lt;duration&gt;20&lt;/duration&gt;
    &lt;width&gt;640&lt;/width&gt;
    &lt;height&gt;480&lt;/height&gt;
    &lt;flv&gt;jenna_123.flv&lt;/flv&gt;
    &lt;screens&gt;
    &lt;screen&gt;jenna.jpg&lt;/screen&gt;
    &lt;/screens&gt;
    &lt;/clip&gt;
    &lt;clip&gt;
    &lt;duration&gt;123&lt;/duration&gt;
    &lt;width&gt;640&lt;/width&gt;
    &lt;height&gt;480&lt;/height&gt;
    &lt;flv&gt;kathy_123.flv&lt;/flv&gt;
    &lt;screens&gt;
    &lt;screen&gt;kathy.jpg&lt;/screen&gt;
    &lt;/screens&gt;
    &lt;/clip&gt;
    &lt;/clips&gt;
   &lt;/video&gt;
  &lt;/videos&gt;
  _XML_;
  
  $xml = new SimpleXMLElement($string);
  
  Header('Content-type: text/xml');
  echo $xml-&gt;asXML();
  ?&gt;
  </code></pre>
  
  <p>but if i try to pull values from db and put in the same hierarchy it doesnt output data in xml. like this</p>
  
  <pre><code>    &lt;?php
       $dbh=mysql_connect($localhost, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error());
       $result = mysql_query("SELECT * FROM 12345_flv.flv WHERE enabled = '1' ORDER BY id DESC") or die('Could not connect: ' . mysql_error());  
  
      $string = '&lt;&lt;&lt;_XML_&lt;videos&gt;&lt;updated&gt;2010-07-20T00:00:00Z&lt;/updated&gt;&lt;video&gt;';
      while ($row = mysql_fetch_array($result)) { 
      $id=$row['id'];
      $title=$row['title'];
      $string .='&lt;id&gt;'.$id.'&lt;/id&gt;';
      $string .='&lt;title&gt;'.$title.'&lt;/title&gt;';
      }
      $string .='&lt;/video&gt;&lt;/videos&gt;_XML_'; 
      $xml = new SimpleXMLElement($string);
      Header('Content-type: text/xml');
  echo $xml-&gt;asXML();
  ?&gt;
  </code></pre>
  
  <p>its output shows &lt;&lt;&lt;<em>XML</em> in the page source .</p>
  
  <p>what i am doing wrong.
  all i want is export the data from mysql into xml using php.</p>
  
  <p>thanks for your time</p>