Posted By

NexusRex on 10/11/06


Tagged

mysql xml


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

millisami
blakeb
jthomassie
willcodeforfood


Create XML file and populate with data from mySQL


 / Published in: PHP
 

URL: http://builder.com.com/5110-6388-5055276.html

  1. if ($num != 0) {
  2.  
  3. $file= fopen("results.xml", "w");
  4.  
  5. $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
  6. ";
  7.  
  8. $_xml .="<site>
  9. ";
  10.  
  11. while ($row = mysql_fetch_array($result)) {
  12.  
  13. if ($row["pageTitle"]) {
  14.  
  15. $_xml .="\t<page title=\"" . $row["pageTitle"] . "\">
  16. ";
  17.  
  18. $_xml .="\t\t<file>" . $row["pageLink"] . "</file>
  19. ";
  20. $_xml .="\t</page>
  21. ";
  22. } else {
  23.  
  24. $_xml .="\t<page title=\"Nothing Returned\">
  25. ";
  26. $_xml .="\t\t<file>none</file>
  27. ";
  28.  
  29. $_xml .="\t</page>
  30. ";
  31. } }
  32.  
  33. $_xml .="</site>";
  34.  
  35. fwrite($file, $_xml);
  36.  
  37. fclose($file);
  38.  
  39. echo "XML has been written. <a href=\"results.xml\">View the XML.</a>";
  40.  
  41. } else {
  42.  
  43. echo "No Records found";
  44.  
  45. } ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: maverickblair on January 22, 2008

how do you implement this? I don't see a connection to a database.

You need to login to post a comment.