PHP - XML - if else
Hi,
I hope somebody can help me out with this.
I use this php script to create an XML document for use in AS3.
The connection works and I get the data if I want.
But when the recordset is empty I want the XML to display a message to make clear there are no data this time.
I cannot get this done.
Can somebody point out to me where I go wrong.
Any help is greatly appreciated.
Here is the script I tried several versions of it though:
-------------------------------
<?php
$link = mysql_connect("zzzz", "zzzz", "zzzz");
mysql_select_db("jonettest");
$query = 'SELECT * FROM zzzz WHERE ag_kop >= "a" AND ag_kop <= "b" ORDER BY ag_kop ASC';
$results = mysql_query($query);
$geen = "no program this month";
$geendatum = "-----";
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
echo "<dataLoaded>\n";
?>
<?php if (!empty($results)) { ?>
<?php while ($line = mysql_fetch_assoc($results)) { ?>
<?php
echo "<verhaal>\n";
echo "<id>" . $line["ag_id"] . "</id>\n";
echo "<datum><![CDATA[" . $line["ag_datum"] . "]]></datum>\n";
echo "<kop><![CDATA[" . $line["ag_kop"] . "]]></kop>\n";
echo "<tekst><![CDATA[<textformat leading='6'>" . $line["ag_tekst"] . "</textformat>]]></tekst>\n";
echo "<info><![CDATA[<textformat leading='6'>" . $line["ag_info"] . "</textformat>]]></info>\n";
echo "</verhaal>\n";
?>
<?php } ?>
<?php } else { ?>
<?php
echo "<verhaal>\n";
echo "<id>" . 2 . "</id>\n";
echo "<datum><![CDATA[" . $geendatum . "]]></datum>\n";
echo "<kop><![CDATA[" . $geen . "]]></kop>\n";
echo "<tekst><![CDATA[<textformat leading='6'>" . $geen . "</textformat>]]></tekst>\n";
echo "<info><![CDATA[<textformat leading='6'>" . $geen . "</textformat>]]></info>\n";
echo "</verhaal>\n";
?>
<?php } ?>
<?php
echo "</dataLoaded>\n";
mysql_close($link);
?>
