Advertisement
Guest User

generate xml

a guest
Apr 12th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3. header("Content-type: name/xml");
  4.  
  5. $host = "localhost";
  6. $user = "root";
  7. $pass = "Briker";
  8. $database = "phonebook";
  9. $ext = "ext";
  10.  
  11. $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
  12. mysql_select_db($database, $linkID) or die("Could not find database.");
  13.  
  14. $query = "SELECT name,number FROM phonebook limit 20";
  15. $resultID = mysql_query($query, $linkID) or die("Data not found.");
  16.  
  17. $xml_output = "<?xml version=\"1.0\"?>\n";
  18. $xml_output .= "<Screen>\n";
  19.  
  20. for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
  21.         $row = mysql_fetch_assoc($resultID);
  22.         $xml_output .= "\t<PhoneBook>\n";
  23.         $xml_output .= "\t<Personel>\n";
  24.         $xml_output .= "\t\t<Name>" . $row['name'] . "</Name>\n";
  25.         $xml_output .= "\t<PhoneNums>\n";
  26.         $xml_output .= "\t\t<PhoneNumstype=$ext>" . $row['number'] . "</PhoneNums>\n";      
  27.         $xml_output .= "\t</PhoneNums>\n";
  28.         $xml_output .= "\t</Personel>\n";
  29.         $xml_output .= "\t</PhoneBook>\n";
  30. }
  31.  
  32. $xml_output .= "</Screen>";
  33.  
  34. echo $xml_output;
  35.  
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement