When need to take data from mysql, we need to use php to get the data and put in a xml file, and then only flash can get the data.
When saving data from flash to mysql, it can directly send to php and insert into mysql table.
Below is the sample script for php to get data from mysql and generate a xml file to save the data:
require "connectdb.php";
$query='SELECT * FROM myguestbook order by id desc';
$result=mysql_query($query);
echo "\n";
echo "\n"; \n";
while($line=mysql_fetch_assoc($result))
{
echo "- \n";
\n";
echo "".$line["name"]." \n";
echo "".$line["comment"]." \n";
echo "\n";
echo "
}
echo "
mysql_close();
Below is the sample script for php to fetch the data from flash and insert into mysql table:
require "connectdb.php";
$name=$_POST['uname'];
$comment=$_POST['ucomment'];
$Today = date("Ymd,l,H:i");
$id=date("YmdHis");
$str_sql="INSERT INTO myguestbook (name,comment,time,id) VALUES ('$name','$comment','$Today','$id');";
if(mysql_query($str_sql))
{
$info= "Save data success!";
}
else
{
$info= "Save data failure!";
}
mysql_close();
echo "&backinfo=".$info."&";
Below is the sample script for flash to save and load the data from mysql.
stop();
var canSend_boo:Boolean=false;
function checkText()
{
if(trim(_nameTi.text)=="")
{
mx.controls.Alert.show("Name is empty£¡");
}else if(trim(_commentTa.text)=="")
{
mx.controls.Alert.show("Message is empty£¡");
}else
{
canSend=true;
}
}
function trim(s:String):String
{
var new_str:String;
new_str=s.split(" ").join("");
new_str=new_str.split("¡¡").join("");
return new_str;
}
state_var="";
var myXML:XML=new XML();
myXML.ignoreWhite=true;
myXML.onLoad=function (success)
{
if (success)
{
loadData();
state_var+="Load XML success.\n";
}
else
{
_outTa.text="Load Data Failed¡£";
}
}
myXML.load("datatoxml.php?n="+random(9999));
function loadData()
{
_outTa.text="";
var nodes=myXML.firstChild.childNodes;
_numLbl.text="Message"+nodes.length+;
for(i=0;i<"nodes.length";i++) ()="" (cansend)senddata();="" (success)="" );="" +="Failed to Load\n" ;="" _commentta.text="" _outta.text="_outTa.text+"Name£ยบ"+nodes[i].childNodes[0].childNodes+"\n";" _savebtn.onrelease="function" checktext();="" data_lv.onload="function(success)" data_lv.sendandload(="" data_lv.ucomment="trim(_commentTa.text);" data_lv.uname="trim(_nameTi.text);" data_lv:loadvars="new" datatosql.php?n="+random(9999), data_lv, " datatoxml.php?n="+random(9999)); _nameTi.text=" else="" function="" if="" loaddata();="" loadvars();="" myxml.load(="" post="" senddata()="" state_var+="Send data......\n" state_var="" var="" {="" };="" }="">