Create XML file and populate with data from mySQL


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your 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. } ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.