I’m writing a script that creates an XML document for a desk phone to load.
It’s working but not quite how I want.
I only want to output a Menu block if the Category Group changes, But I’m not sure how to test for that in my code.
Here is the output I have currently:
[php]
?xml version=“1.0” encoding=“UTF-8”?>
Here is the output I want:
[php]?xml version=“1.0” encoding=“UTF-8”?>
Here is my script:
[php]<?php
header(“Content-type: text/xml”);
$host = “localhost”;
$user = “web”;
$pass = “28t46wgjhrksf98yhkj”;
$database = “test”;
$linkID = mysql_connect($host, $user, $pass) or die(“Could not connect to host.”);
mysql_select_db($database, $linkID) or die(“Could not find database.”);
$query = “SELECT CategoryGroup,ContactName,Phone1,Phone2,Phone3 FROM phonebook ORDER BY CategoryGroup”;
$resultID = mysql_query($query, $linkID) or die(“Data not found.”);
$xml_output = “<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n”;
$xml_output .= “\n”;
$xml_output .= “Yealink\n”;
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= “\t<Menu Name=”" . $row[‘CategoryGroup’] . “”>\n";
$xml_output .= “\t\t<Unit Name=”" . $row[‘ContactName’] . “” default_photo=“Resource:” " . “Phone3=”" . $row[‘Phone3’] . “” " . “Phone2=”" . $row[‘Phone2’] ."" " . “Phone1=”" . $row[‘Phone1’] . “”/>\n";
$xml_output .= “\t\n”;
}
$xml_output .= “”;
echo $xml_output;
?>
[/php]