Hello I have been trying to make a forum and I did that correctly but the problem is that the whole page was reloading which means that if you have too much comments on the page it will always redirect you to the top and you have to scroll down to the last comment so I learned ajax to fix that but however I face up this problem says "error on line 28 at column 323: Entity 'ldquo' not defined" what is the problem please explain here is the PHP that generates XML
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
?>
<?php
require 'connect.inc.php';
$sql= $db->query("SELECT * FROM comments");
$results = $sql->fetchAll(PDO::FETCH_ASSOC);
echo '<comments>'."
";
foreach($results as $result)
{
echo '<comment>'."
";
echo $result['post']."
";
echo '</comment>'."
";
}
echo '</comments>';
?>
It seems releated to your $results. I try your code with the fake $results, it workes well. BTW, the fake $results is : $results = array(array('id' => 1, 'post' => 'a'), array('id' =>2 , 'post' => 'b'));
The demo code:
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
?>
<?php
#require 'connect.inc.php';
#$sql= $db->query("SELECT * FROM comments");
#$results = $sql->fetchAll(PDO::FETCH_ASSOC);
$results = array(array('id' => 1, 'post' => 'a'), array('id' =>2 , 'post' => 'b'));
echo '<comments>'."
";
foreach($results as $result)
{
echo '<comment>'."
";
echo $result['post']."
";
echo '</comment>'."
";
}
echo '</comments>';
?>
In php you can convert array to xml data
$test_array = array (
'bla' => 'blub',
'foo' => 'bar',
'another_array' => array (
'stack' => 'overflow',
),
);
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($test_array, array ($xml, 'addChild'));
print $xml->asXML();
O/P:-
<?xml version="1.0"?>
<root>
<blub>bla</blub>
<bar>foo</bar>
<overflow>stack</overflow>
</root>