Hello I'm having some trouble with a certain PHP file. I have a database created on my local server and need to use PHP to generate XML from the tables in the database.
The code works when I try to retrieve data from only one table but I can't seem to figure out how to query multiple tables.
This is a snippet of the code:
$connection = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $connection) or die("Could not find database.");
$query = "SELECT * FROM department";
$resultSet = mysql_query($query, $connection) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<school>\n";
for($x = 0 ; $x < mysql_num_rows($resultSet) ; $x++){
$row = mysql_fetch_assoc($resultSet);
$xml_output .= "\t<department>\n";
$xml_output .= "\t\t<name>" . $row['name'] . "</name>\n";
$xml_output .= "\t\t<code>" . $row['code'] . "</code>\n";
$xml_output .= "\t</department>\n";
$xml_output .= "\t<program>\n";
$xml_output .= "\t\t<name>" . $row['name'] . "</name>\n";
$xml_output .= "\t\t<department>" . $row['department'] . "</department>\n";
$xml_output .= "\t\t<co-op>" . $row['co-op'] . "</co-op>\n";
$xml_output .= "\t</program>\n";
The department table contains values of name and code.
The program table contains values of name, department and co-op.
My question is how would I go about printing all of the contents of the department and program tables?