Hi Everyone,
This is my first question on the forum. I need help with XML plugin - How to use it. I am trying to pull data from mysql database using ajax and XML. But I cannot load the XML into construct 2. I use the following php to pull the data from the database and convert it into XML. But I do not know how to load it into construct 2. Can someone help me?
Here is the php code I use --> Converting database information in XML format.
<?php
header("Content-Type: text/xml"); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
// Connect to your MySQL database whatever way you like to here
$dbhost = "xxx";
$dbuser = "xxx";
$dbpass = "xxx";
$dbname = "xxx";
mysql_connect("$dbhost","$dbuser","$dbpass") or die (mysql_error());
mysql_select_db("$dbname") or die ("no database");
// Execute the Query on the database to select items(20 in this example)
$sql = mysql_query("SELECT * FROM teacher ORDER BY ID LIMIT 0, 10");
while($row = mysql_fetch_array($sql)){
// Set DB variables into local variables for easier use
$id = $row["ID"];
$teacherName = $row["teacherName"];
$teacherPassword = $row["teacherPassword"];
$email = $row["email"];
$date = $row["date"];
// Start filling the $xmlBody variable with looping content here inside the while loop
// It will loop through 20 items from the database and render into XML format
$xmlBody .= '
<Data>
<DataID>' . $id . '</DataID>
<TeacherName>' . $teacherName . '</TeacherName>
<TeacherPassword>' . $teacherPassword . '</TeacherPassword>
<Email>' . $email . '</Email>
<Date>' . $date . '</Date>
</Data>';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody; // output the gallery data as XML file for flash
?>