
July 8th, 2012, 08:36 AM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 2
Time spent in forums: 12 m 10 sec
Reputation Power: 0
|
|
|
ActionScript 3 - ActionScript 3 Display From PHP Variable.
What do i do so that flash display all the results from php in the looped movieclips?
Can someone help me? I'm trying to extract out the data from php using array so that every rows have different data according to the rows in mysql. But right now only one data from a row of mysql seem to be displayed. However when i traced.. it displayed all the data. But how do i assign to the
looped newContainer such tht, each of the newContainer have different rows of data?
What should I do so that the each newContainer have different event names, dates, slots left coming from the 8 results respectively? And not just one newContainer displaying only one result the data. I have like 8 rows to be displayed in flash from my sql..
this is my code..
import flash.events.MouseEvent;
import flash.events.Event;
import fl.motion.MotionEvent;
import flash.net.URLVariables;
import flash.display.MovieClip;
import flashx.textLayout.elements.Configuration;
var ctr:int = 0;
var nowate = new Date();
var myurl:String = "http://localhost:8888/eventspictures/getdata.php";
var containers:Array = [];
var scriptLoader:URLLoader = new URLLoader();
var scriptRequest:URLRequest = new URLRequest();
scriptRequest.url = myurl + "?ck=" + now.getTime();
scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccess);
scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleError);
scriptRequest.method = URLRequestMethod.POST;
scriptLoader.load(scriptRequest);
function handleLoadSuccess(evt:Event):void
{
for (var j:Number = 0; j <4; j++)
{
var newContainer:MovieClip = new con();
newContainer.name = String(ctr);
newContainer.y = j*80 +65;
newContainer.x= 16;
stage.addChild(newContainer);
containers.push(newContainer);
var variables:URLVariables = new URLVariables(evt.target.data);
trace(variables.output);
var parse:String = variables.output;
var parsed:Array = parse.split("<|>");
var tab:String = ' ';
var eventname:String = '';
var date:String='';
var slotsleft:String='';
// different variable names to assign to different column names(etc; eventname, date, slotsleft)
// loop through.. start from O
for (var i:Number = 0; i<parsed.length-1; i++)
{
trace(parsed[i]);
var item:String = parsed[i];
var itemarray:Array = item.split(",");
eventname += itemarray[2] + tab + "<br>";
date += itemarray[3] + tab;
slotsleft += itemarray[4] + tab;
trace(eventname);
}
}
newContainer.eventname_txt.htmlText = eventname;
newContainer.date_txt.htmlText= date;
newContainer.slotsleft_txt.htmlText=slotsleft;
//slotsleft_txt.x = 270;
}
function handleError(evt:IOErrorEvent):void
{
}
backbutton_mc.addEventListener(MouseEvent.CLICK, goHomePage);
function goHomePage (evt:Event):void{
gotoAndPlay("dashboard");
for (var j:int = 0; j < containers.length; j++)
{
stage.removeChild( containers[j] );
}
}
stop();
or issit a php error?
Here's the php code..
<?php
$_POST['orderby']= "date";
$_POST['sortby']= "asc";
$host = 'localhost'; // or '127.0.0.1'
$user ='root'; //FTP login name if own server
$password= 'root'; // FTP PASSWORD
$connection = mysql_connect($host,$username,$password);
$connection = mysql_connect($host, $user, $password);
if (!$connection) {
echo 'error=' . mysql_error() . '&';
die('Could not connect ' . mysql_error());
}
//echo 'Connected successfully' ."\n<br />";
// * means everything
$database = 'eventspictures';
$db = mysql_select_db($database, $connection);
if (!$db) {
echo 'error=' . mysql_error() . '&';
die ('Not connected : ' . mysql_error());
}
//echo 'Database Selected successfully'."\n<br />";
//3. Build a query
if ($_POST['orderby']){
$query= 'select * from eventsdata order by '.$_POST['orderby'].' '.$_POST['sortby'];
}else{
$query= 'select * from eventsdata';
// select everything from eventsdata
}
$results = mysql_query($query, $connection) or die('Query not run' . mysql_error());
//echo 'Query run<br>';
//4. Fetch data and 5. Loop to display data
/*while($row = mysql_fetch_array($results)){
extract ($row);
echo "$id, $admin, $name \n<br>";
}
*/
//6. format for flash
while($row = mysql_fetch_array($results)){
extract ($row);
$output .= "$id,$image,$eventname,$date,$slotsleft".'<|>';
}
echo 'output='.urlencode($output);
//7. database close
mysql_close($connection); // only if you use mysql_connect()
?>
|