matbury
03-01-2008, 03:43 PM
Hi,
I'm doing a project with SQL, PHP and Flash for e-learning. It's a PHP wrapper that manages combining SWFs with XML files to present lessons to students. It's still at the experimental stage and I just have simple question, hopefully with a simple answer:
How do I get the string value, retrieved from MySQL via PHP, '$xmlurl' into the Flash SWF movie?
I'm ore of an Actionscript developer than a PHP developer so it's the PHP bit that's more of a problem for me.
Here's my PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
// Database access info
include("db.php");
// Connect to database
mysql_connect($host,$user,$pass);
mysql_select_db($database);
// Retrieve entire table (it's very small at the moment)
$result = mysql_query("SELECT * FROM `mdl_flashnew_lessons`");
// Get the table row number from the URL query string - e.g. ?rowno=3
// TODO retrieve the corresponding XML file for the lesson from
// the database
$row = $_GET['rowno'];
// Make sure the 'rowno' query string variable isn't greater
// than the number of rows in the database table
// (This needs to be more dynamic i.e. get the length of the SQL table)
if ($row > 8) {
$row = 1;
}
// Assign the data to variables
$xmlurl = mysql_result($result,$row,'xmlurl');
$swfurl = mysql_result($result,$row,'swfurl');
$swfname = mysql_result($result,$row,'swfname');
$width = mysql_result($result,$row,'width');
$height = mysql_result($result,$row,'height');
$version = mysql_result($result,$row,'version');
$bgcolor = mysql_result($result,$row,'bgcolor');
// TODO - pass the $xmlurl string into the presentation SWF
// How?
// Always close the database connection when
// you've finished with it!
mysql_close();
// Define HTML page <head> parameters including CSS
$css = "<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Embed using PHP and SWFObject experiment</title><style type=\"text/css\">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #666666;
}
-->
</style>
</head>";
// SWFObject embed code uses variables retrieved from MySQL database
// and a separate swfobject.js script that needs to be included
/*
SWFObject can also pass extra variables into the Flash SWF
It would be nice to be able to get the lesson's corresponding XML file
and pass it in here.
Does anyone know if you can pass an XML object in this way?
*/
$embed_swf = "<body><script type='text/javascript' src='swfobject.js'></script>
<div id='content'>To view the Flash content, please enable JavaScript in your browser.</div>
<script type='text/javascript'>
var so = new SWFObject('$swfurl', '$swfname', '$width', '$height', '$version', '$bgcolor');
so.addParam('wmode', 'transparent');
so.write('content');
</script>";
// Print out the database SWF embed data to the screeen
$embed_info = "<br />
<p class=\"style1\">This is an experiment using PHP code to output Javascript code to embed a SWF. If this works, you should see a Flash movie clip on the screen above. The specific variables to embed the SWF were retrieved from a MySQL database. Here they are:</p>
<p class=\"style1\">SQL rowno: '$row'</p>
<p class=\"style1\">SWF url: '$swfurl'</p>
<p class=\"style1\">SWF url: '$xmlurl'</p>
<p class=\"style1\">SWF name: '$swfname'</p>
<p class=\"style1\">SWF width: '$width'</p>
<p class=\"style1\">SWF height: '$height'</p>
<p class=\"style1\">SWF version: '$version'</p>
<p class=\"style1\">SWF bgcolor: '$bgcolor'</p></body>";
// Display the page
echo $css.$embed_swf.$embed_info;
?>
</html>
I'm doing a project with SQL, PHP and Flash for e-learning. It's a PHP wrapper that manages combining SWFs with XML files to present lessons to students. It's still at the experimental stage and I just have simple question, hopefully with a simple answer:
How do I get the string value, retrieved from MySQL via PHP, '$xmlurl' into the Flash SWF movie?
I'm ore of an Actionscript developer than a PHP developer so it's the PHP bit that's more of a problem for me.
Here's my PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
// Database access info
include("db.php");
// Connect to database
mysql_connect($host,$user,$pass);
mysql_select_db($database);
// Retrieve entire table (it's very small at the moment)
$result = mysql_query("SELECT * FROM `mdl_flashnew_lessons`");
// Get the table row number from the URL query string - e.g. ?rowno=3
// TODO retrieve the corresponding XML file for the lesson from
// the database
$row = $_GET['rowno'];
// Make sure the 'rowno' query string variable isn't greater
// than the number of rows in the database table
// (This needs to be more dynamic i.e. get the length of the SQL table)
if ($row > 8) {
$row = 1;
}
// Assign the data to variables
$xmlurl = mysql_result($result,$row,'xmlurl');
$swfurl = mysql_result($result,$row,'swfurl');
$swfname = mysql_result($result,$row,'swfname');
$width = mysql_result($result,$row,'width');
$height = mysql_result($result,$row,'height');
$version = mysql_result($result,$row,'version');
$bgcolor = mysql_result($result,$row,'bgcolor');
// TODO - pass the $xmlurl string into the presentation SWF
// How?
// Always close the database connection when
// you've finished with it!
mysql_close();
// Define HTML page <head> parameters including CSS
$css = "<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Embed using PHP and SWFObject experiment</title><style type=\"text/css\">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #666666;
}
-->
</style>
</head>";
// SWFObject embed code uses variables retrieved from MySQL database
// and a separate swfobject.js script that needs to be included
/*
SWFObject can also pass extra variables into the Flash SWF
It would be nice to be able to get the lesson's corresponding XML file
and pass it in here.
Does anyone know if you can pass an XML object in this way?
*/
$embed_swf = "<body><script type='text/javascript' src='swfobject.js'></script>
<div id='content'>To view the Flash content, please enable JavaScript in your browser.</div>
<script type='text/javascript'>
var so = new SWFObject('$swfurl', '$swfname', '$width', '$height', '$version', '$bgcolor');
so.addParam('wmode', 'transparent');
so.write('content');
</script>";
// Print out the database SWF embed data to the screeen
$embed_info = "<br />
<p class=\"style1\">This is an experiment using PHP code to output Javascript code to embed a SWF. If this works, you should see a Flash movie clip on the screen above. The specific variables to embed the SWF were retrieved from a MySQL database. Here they are:</p>
<p class=\"style1\">SQL rowno: '$row'</p>
<p class=\"style1\">SWF url: '$swfurl'</p>
<p class=\"style1\">SWF url: '$xmlurl'</p>
<p class=\"style1\">SWF name: '$swfname'</p>
<p class=\"style1\">SWF width: '$width'</p>
<p class=\"style1\">SWF height: '$height'</p>
<p class=\"style1\">SWF version: '$version'</p>
<p class=\"style1\">SWF bgcolor: '$bgcolor'</p></body>";
// Display the page
echo $css.$embed_swf.$embed_info;
?>
</html>