Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-19-2012, 04:46 PM   #1
Grobi93
AS3 Nab
 
Join Date: Mar 2012
Posts: 14
Send a message via Skype™ to Grobi93
Default Sending a matrix from PHP to AS3

Hello!
I have a little problem. I am trying to send a two dimensional array/matrix from a PHP code to an AS3 code. My solution simply isn't working. Here is my code which reffers to the sending:

The kerdesvalasz table has the questions and answers in it, exactlye 17 rows and 6 columns + 1column is the PRIMARY KEY which is named id.

//Kerdes is quesiton, adatok is data, helyes means correct and valasz is answer in English.

AS3:
ActionScript Code:
var loader:URLLoader=new URLLoader(); loader.dataFormat=URLLoaderDataFormat.VARIABLES; request.method=URLRequestMethod.POST; start_btn.addEventListener(MouseEvent.CLICK,startquiz); var adatok:Array = []; var i:int = 0; var j:int = 0; for(i=0;i<17;i++) {     adatok[i] = []///defining a matrix?? } function startquiz(e:MouseEvent):void { var request:URLRequest=new URLRequest("adatatvitel.php"); var loader:URLLoader=URLLoader(e.target); var vars:URLVariables=new URLVariables(loader.data); for(i=0;i<17;i++)  {  for(j=0;j<5;j++)   {       adatok[i][j] = vars.adatok;   }   i++;  }  }

PHP:
PHP Code:
<?php

require("db.php");

$sql "SELECT * FROM kerdesvalasz";
$result mysql_query($sql) or die(mysql_error());

$adatok = array
 (
  
"kerdes" => array
  (
  ),
  
"valasz1" => array
  (
  ),
  
"valasz2" => array
  (
  ),
  
"valasz3" => array
  (
  ),
  
"valasz4" => array
  (
  ),
  
"helyes" => array
  (
  )
 );
 
$i=0;
while(
$row mysql_fetch_array($result))
{
  
$adatok['kerdes'][$i] = $row ['kerdes'];
  
$adatok['valasz1'][$i] = $row ['valasz1'];
  
$adatok['valasz2'][$i] = $row ['valasz2'];
  
$adatok['valasz3'][$i] = $row ['valasz3'];
  
$adatok['valasz4'][$i] = $row ['valasz4'];
  
$adatok['helyes'][$i] = $row ['helyes'];
  
$i++;  
}

echo 
"adatok=$adatok";
?>
Thanks in advance!

Last edited by Grobi93; 04-19-2012 at 04:50 PM.
Grobi93 is offline   Reply With Quote
Old 04-19-2012, 05:47 PM   #2
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

Use XML or Json to pass your data back to your app (amf is another option). Anything else is just a pain and not professional.
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 04-19-2012, 07:12 PM   #3
Grobi93
AS3 Nab
 
Join Date: Mar 2012
Posts: 14
Send a message via Skype™ to Grobi93
Default

Thanks for the advice, but I don't have enough time to learn another language's basics. I need to finish this project in 3 days.
Grobi93 is offline   Reply With Quote
Old 04-19-2012, 07:19 PM   #4
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

they're not really languages...

they're more like mark-up styling for serializing data.

And most languages have frameworks to deal with them. AS3 has a set of classes for easily manipulating XML. And I believe there are libraries out there for Json.

And AMF is built right into Flash... it's Action Message Format, it's Adobe's serialization technique for sending messages between things like Flash and Flash Media Server.




If you want to do web coding... serializing data is something you're going to NEED to learn! DOn't worry, it's not hard. 3rd party formats and tools exist so that 1) there are standards, and 2) they're easy to learn and use. This is why ASWC said "Anything else is just a pain and not professional"... standards are a good thing.
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!

Last edited by lordofduct; 04-19-2012 at 07:22 PM.
lordofduct is offline   Reply With Quote
Old 04-19-2012, 07:42 PM   #5
Grobi93
AS3 Nab
 
Join Date: Mar 2012
Posts: 14
Send a message via Skype™ to Grobi93
Default

I understand but I just don't have the time right now.
Grobi93 is offline   Reply With Quote
Old 04-19-2012, 07:54 PM   #6
jsprclimber123
Breaking things...
 
Join Date: Jan 2010
Posts: 635
Default

Then you have a problem. Not taking the time to do things right so it's done quicker is, to rightly quote ASWC, "a pain and not professional".

To help along with pushing this to XML, I'd suggest echoing each row as an XML node. So you could do something like this:

Code:
<rows>
<?php
while($row = mysql_fetch_assoc($result)){
echo '<row>'; echo '<kerdes>'.$row['kerdes'].'</kerdes>'; echo '<valasz1>'.$row['valasz1'].'</valasz1>'; echo '<valasz2>'.$row['valasz2'].'</valasz2>'; echo '<valasz3>'.$row['valasz3'].'</valasz3>'; echo '<valasz4>'.$row['valasz4'].'</valasz4>'; echo '<helyes>'.$row['helyes'].'</helyes>'; echo '</row>';
}
?>
</rows>
will result in:

Code:
<rows>
<row>
<kerdes>kerdes from row 1</kerdes> <valasz1>valasz1 from row 1</valasz1> <valasz2>valasz2 from row 1</valasz2> <valasz3>valasz3 from row 1</valasz3> <valasz4>valasz4 from row 1</valasz4> <helyes>helyes from row 1</helyes>
</row> etc...
</rows>
From there, you can parse the XML in flash as needed. Best of luck with your project.
jsprclimber123 is offline   Reply With Quote
Old 04-19-2012, 08:06 PM   #7
Grobi93
AS3 Nab
 
Join Date: Mar 2012
Posts: 14
Send a message via Skype™ to Grobi93
Default

Thank you! I have changed my mind and started watching some tut videos thanks for the code
Grobi93 is offline   Reply With Quote
Old 04-19-2012, 09:07 PM   #8
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

Quote:
Originally Posted by lordofduct View Post
And I believe there are libraries out there for Json.
There is now a JSON class built-in in FP11.
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 04-19-2012, 09:14 PM   #9
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

You can use my DatabaseConnect PHP class (attached) which outputs xml. You use it that way:
PHP Code:
require('DatabaseConnect.php');
$dbconnect = new DatabaseConnect('yourdbserver''yourusername''yourpassword');
$dbconnect->init();
$dbconnect->selectDB('yourdbname');
$yourquery 'SELECT * FROM kerdesvalasz';
$mydata $dbconnect->getQuery($yourquery"root");
print(
$mydata->asXML()); 
Attached Files
File Type: zip DatabaseConnect.zip (1.3 KB, 36 views)
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:12 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.