flex and php
After building the user interface in MXML for my search application, I needed to go to my database and somehow retrieve records to display in the presentation tier. After reading this article, Exchanging Data, I adopted the approach demonstrated in the tutorial and understood how to apply this to my application.
Basically, I needed to trigger my application to call a PHP script that communicated with my MySQL database and returned this data back to my Flex application in XML format.
Here's part of the script I wrote in PHP that formats data from my query into XML:
echo "<events>";
while($row = mysql_fetch_array($qEvents)) {
echo "<event id=\"{$row['event_id']}\">";
echo "<name>{$row['event_name']}</name>";
echo "<description>".str_replace("&", "&", $row['event_description'])."</description>";
echo "<price>{$row['event_price']}</price>";
echo "<venue>{$row['venue_name']}</venue>";
echo "<address>{$row['address_line_1']} {$row['address_line_2']} {$row['city']} {$row['state']}</address>";
echo "<startdate>".date("m/d/Y",$row['dtm_start'])."</startdate>";
echo "<starttime>".date("g:i A",$row['dtm_start'])."</starttime>";
echo "<enddate>".date("m/d/Y",$row['dtm_end'])."</enddate>";
echo "<endtime>".date("g:i A",$row['dtm_end'])."</endtime>";
echo "<weblink>{$row['url_info']}</weblink>";
echo "<ticketlink>{$row['url_tickets']}</ticketlink>";
echo "</event>";
}
echo "</events>";
To view the XML result, click here.
0 comments:
Post a Comment