Anyone know how to incorporate PHP and MySQL in Flash?
I've been reading this book--PHP 5 for Flash but I don't really like the way the author writes and explains things. Also...there are a lot of things that he doesn't explain along the way and creates these flash movies that are way more complex than I need.
I am only trying to load a few fields from the database (id, date, city and state) and display them in a dynamic text field in a list.
I want to echo through PHP. It is for my band's site. I designed everything in Flash and now I've been learning PHP and MySQL and want to be able to load all my tour dates in my flash movie.
Like I said before...I only need to load the fields id, date, city and state from the database.
Here's what I built to display it in HTML the way I want it:
PHP Code:
<?php
include ('./includes/config.inc.php');
require_once ('./Connections/dbc.php'); // Connect to the db.
$today = date('Ymd');
// Make the query.
$query = "SELECT id, city, state, venue, time, DATE_FORMAT(date, '%m/%d/%y') AS date FROM tour WHERE date >= $today ORDER BY DATE_FORMAT(date, '%Y %m %d') ASC";
$result = @mysql_query ($query); // Run the query.
$num = mysql_num_rows($result);
if ($num > 0) { // If it ran OK, display the records.
echo '
<table>
<tr>
<td align="left" width="100"><span class="bold">Date</span></td>
<td align="left" width="160"><span class="bold">City/State</span></td>
<td align="left" width="60"><span class="reg"> </span></a></td>
</tr>';
// Fetch and print all the records.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '
<tr>
<td align="left" width="100"><span class="reg"> ' . $row['date'] . '</span></td>
<td align="left" width="160"><span class="reg"> ' . $row['city'] . ', ' . $row['state'] .'</span></td>
<td align="left" width="60"><span class="reg"><a href="details.php?id=' . $row['id'] . '">details</span></a></td>
</tr>';
}
echo '</table>';
mysql_free_result ($result); // Free up the resources.
} else { // If it did not run OK.
echo '<p><span class="reg">There are currently no planned tour dates.</span></p>';
}
mysql_close(); // Close the database connection.
?>
I need to figure out 2 things:
1. How to change this script to output the data in flash correctly.
2. How to write the correct actionscript.
and if flash want to communicate to php and get smt from it you must use LoadVars:
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
rate = result_lv.new_rate; // data from php page
} else {
fscommand('alert', 'Flash couldn\'t connect to server.');
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.user_rate = user_rate; // data that must be send to php
send_lv.sendAndLoad("/game/rate.php?", result_lv, "POST");
I'm still needing some help with this. I'm struggling with understanding the actionscript that I would need to write in order to parse in the data from PHP.
I know that alot of folks just use XML to parse data into Flash. Can I edit my PHP script to output XML and do it that way?
How would my actionscript look? Please remember that there will be many results.