Hi guys
can anyone look at this code and help work this flash poll system out?
It uses php and mysql db…so far I can’t display the results of the votes;
instead on each column on the swf that should display the number of votes for each option i get the following text: NaN % Votes
Here is the actionscript and the php code:
on the first keyframe named “choose”:
stop();
submit_btn.enabled = false;
var loadVars_in:LoadVars = new LoadVars();
var loadVars_out:LoadVars = new LoadVars();
loadVars_in.onLoad = function(success) {
if (success) {
//If the values are in goto results
gotoAndStop("result");
} else {
//notify of failure
}
};
// Does the user wants to vote?
listenerObject = new Object();
listenerObject.click = function(eventObject) {
submit_btn.enabled = true;
};
radioGroup.addEventListener("click", listenerObject);
//Vote
submit_btn.onRelease = function() {
var selectedNum:Number = radioGroup.selectedData;
loadVars_out.choice = selectedNum;
loadVars_out.sendAndLoad("vote.php",loadVars_in,"POST");
};
on the next keyframe named “results”:
//How many votes in total?
var totalVotes:Number = loadVars_in.totalVotes;
var end:String
for(i=1;i<=4;i++){
vote = loadVars_in["vote" + i + "total"]
procent = Math.round(( vote / totalVotes) * 100);
if(votes==1){
end = "Vote";
} else {
end = "Votes";
}
_root["graph"+i+"_mc"].bar_mc._xscale = procent;
_root["graph"+i+"_mc"].procent.text = procent + " % - " + vote + end;
}
and the php code that should communicate and display the results in the swf is the following:
<?
$choice =$_POST['choice'];
$user="xxxxxxx";
$password="xxxxxxx";
$database="xxxxxxx";
$server="xxxxxxx";
mysql_connect($server,$user,$password);
@mysql_select_db($database) or die( "Unable to connect to database");
// what choice did the user choose in flash?
if($choice == 1){
$query="UPDATE votesystem SET vote1=vote1+1";
}
if($choice == 2){
$query="UPDATE votesystem SET vote2=vote2+1";
}
if($choice == 3){
$query="UPDATE votesystem SET vote3=vote3+1";
}
if($choice == 4){
$query="UPDATE votesystem SET vote4=vote4+1";
}
mysql_query($query);
//Get values from the database
$query="SELECT * FROM votesystem";
$result=mysql_query($query);
mysql_close();
//What are the values from the database?
$vote1_out=mysql_result($result,0,"vote1");
$vote2_out=mysql_result($result,0,"vote2");
$vote3_out=mysql_result($result,0,"vote3");
$vote4_out=mysql_result($result,0,"vote4");
//Votes in total
$total=$vote1_out+$vote2_out+$vote3_out+$vote4_out;
//Info to send back to flash:
$values="&totalVotes=$total&vote1total=$vote1_out&vote2total=$vote2_out&vote3total=$vote3_out&vote4total=$vote4_out";
echo "$values";
?>
Please let me know
thank you