1 |
<?php |
2 |
header("Content-type: text/xml"); |
3 |
error_reporting(0); |
4 |
|
5 |
$hostname = "tuhost"; |
6 |
$databasename = "nombredetubasededatos"; |
7 |
$username = "tuusuario"; |
8 |
$password = "tucontraseņa"; |
9 |
|
10 |
print "<?xml version='1.0' encoding='iso-8859-1'?>"; |
11 |
?> |
12 |
<node> |
13 |
<?php |
14 |
$conn = mysql_connect($dbhostname, $username, $password); |
15 |
if(!$conn) { |
16 |
print "<status code=\"0\">Error connecting to database\n".mysql_error()."</status>\n"; |
17 |
} |
18 |
else if(!mysql_select_db($databasename)) { |
19 |
print "<status code=\"0\">Error selecting database\n".mysql_error()."</status>\n"; |
20 |
} |
21 |
else { |
22 |
$result = mysql_query("SELECT e.link,s.nombre FROM enlaces e,secciones s WHERE e.seccionid=s.id ORDER BY s.nombre, e.link DESC"); |
23 |
if(!$result) { |
24 |
print "<status code=\"0\">Error querying database\n".mysql_error()."</status>\n"; |
25 |
} |
26 |
else { |
27 |
//CODIGO PARA LLAMADAS A FUNCION. |
28 |
getResults($result); |
29 |
} |
30 |
} |
31 |
|
32 |
function getResults($result){ |
33 |
$oldsec=""; |
34 |
while($row = mysql_fetch_assoc($result)) { |
35 |
extract($row); |
36 |
if($oldsec!=$nombre && $oldsec!=""){print "</node>\n";} |
37 |
if($oldsec!=$nombre){print "<node label='$nombre'>\n";$oldsec=$nombre;} |
38 |
print "<node label='$link' isBranch='true' />\n"; |
39 |
} |
40 |
print "</node>\n"; |
41 |
} |
42 |
?> |
43 |
</node> |