I'm having a couple of (possibly related) problems.
1) When I run this code as-is, I get an extra output to the screen...usually three numbers such as "559" or "205". The output appears in the HTML exactly where I've included "phpsqlajax_genxml.php" so that appears to the culprit.
I have checked both "phpsqlajax_genxml.php" and "phpsqlajax_expectedoutput.xml" (doing multiple searches) and there's nothing in there like the unwanted output that appears. Where are these numbers coming from?
2) In the phpsqlajax_genxml.php code if I uncomment the header() function I receive: "Warning: Cannot modify header information - headers already sent by..."
It seems that the header function is attempting to modify something other than the newly created XML file? How do I correct this so that the header function is only attempting to modify the "phpsqlajax_expectedoutput.xml" file.
Thanks!
Here's the code for phpsqlajax_genxml.php:
Expand|Select|Wrap|Line Numbers
- <?php require("phpsqlajax_dbinfo.php");
- // Start XML file, create parent node
- $dom = new DOMDocument("1.0");
- $node = $dom->createElement("markers");
- $parnode = $dom->appendChild($node);
- // Opens a connection to a MySQL server
- $connection=mysql_connect ($host, $username, $password);
- if (!$connection) { die('Not connected : ' . mysql_error());}
- // Set the active MySQL database
- $db_selected = mysql_select_db($database, $connection);
- if (!$db_selected) {
- die ('Can\'t use db : ' . mysql_error());
- }
- // Use previous query
- $result = mysql_query($query);
- if (!$result) {
- die('Invalid query: ' . mysql_error());
- }
- //header("Content-type: text/xml");
- // Iterate through the rows, adding XML nodes for each
- while ($row = @mysql_fetch_assoc($result)){
- // ADD TO XML DOCUMENT NODE
- $node = $dom->createElement("marker");
- $newnode = $parnode->appendChild($node);
- $newnode->setAttribute("name",$row['name']);
- $newnode->setAttribute("address1", $row['address1']);
- $newnode->setAttribute("address2", $row['address2']);
- $newnode->setAttribute("neighborhood", $row['neighborhood']);
- $newnode->setAttribute("telephone", $row['telephone']);
- $newnode->setAttribute("lat", $row['lat']);
- $newnode->setAttribute("lng", $row['lng']);
- if ($row['num_user_ratings'] == 0) {
- } else {
- $num_user_ratings = $row['num_user_ratings'];
- $user_rating = $row['user_rating'];
- $rating_score = $user_rating/$num_user_ratings;
- $newnode->setAttribute("rating_score", $rating_score);
- }
- }
- echo $dom->save("phpsqlajax_expectedoutput.xml");?>
Expand|Select|Wrap|Line Numbers
- <?php
- //$query removed for brevity
- $result = mysql_query($query) or die(mysql_error());
- ?>
- </div>
- <table border="0">
- <tr>
- <td valign="top">
- <div id="resultsbox">
- <table border="0">
- <?php
- while ($row = mysql_fetch_array($result)) {
- // Several echos removed for brevity
- echo "</TD></TR>";
- }
- //This is where the extra output ("559" or "205" etc.) appears.
- include 'phpsqlajax_genxml.php';
- ?>
- </table>
- </div>
- </td>
- <td valign="top">
- <div id="map" class="map" style="width: 380px; height: 320px"></div></td>
- </td>
- </tr>
- </table>
- <?php
- }
- ?>
- </div>