A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: XML delima (again)

  1. #1
    Senior Member
    Join Date
    Jul 2002
    Location
    New Mexico
    Posts
    101

    XML delima (again)

    I have xml data produced by a php page and I am trying to get information TO the php page for it to go to the database and retrieve the data and put it in xml format for flash. the problem I am having is getting the user data TO the php page...here is what I am trying to get to work:

    Code:
    serverdate = new Array();
    servercurrentQuestion = new Array();
    serveryouranswer = new Array();
    var my_xml1 = new XML();
    my_xml1.ignoreWhite = true;
    my_xml1.onLoad = function(success) {
    	if (success) {
    		
    	var myitems = my_xml1.firstChild.childNodes;
    	for (var i = 0; i<myitems.length; i++) {
    			serverdate[i] = (myitems[i].firstChild.firstChild);	//date
    			servercurrentQuestion[i] = (myitems[i].firstChild.nextSibling.firstChild);
    			serveryouranswer[i] = (myitems[i].firstChild.nextSibling.nextSibling.firstChild);
    			M1testDate = serverdate[i];
    			M1lastQuestion = servercurrentQuestion[i];
    		}
    			
    	}
    };
    username = "someusername";
    email = "someemail";
    testformat = "MATH";
    testnumber = "1";
    my_xml1.load("http://www.mydomain.com/flashdatatest.php?name="+username+"&email="+email+"&testtype="+testformat+"&testnumber="+testnumber);

    Here is my php code:
    Code:
    mysql_select_db($database_MyConnect, $MyConnect);
    $name = $_GET['username'];
    $email = $_GET['email'];
    $testtype = $_GET['testformat'];
    $testnumber = $_GET['testnumber'];
    $sql = "SELECT YourChoice, currentQuestion, DateTaken FROM anstrackuser WHERE Username = '$name' AND Email = '$email' AND TestType = '$testtype' AND TestName = 'GMAT' AND TestNumber = '$testnumber' ORDER BY anstrackuser.currentquestion ASC ";
    $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
    
    $xml_output = "<?xml version=\"1.0\"?>\n"; 
    $xml_output .= "<entries>\n"; 
    
    for($x = 0 ; $x < mysql_num_rows($result) ; $x++){ 
        $row = mysql_fetch_assoc($result); 
        $xml_output .= "\t<entry>\n"; 
        $xml_output .= "\t\t<date>" . $row['DateTaken'] . "</date>\n"; 
        $xml_output .= "\t\t<currentQuestion>" . $row['currentQuestion'] . "</currentQuestion>\n"; 
    	$xml_output .= "\t\t<yourans>" . $row['YourChoice'] . "</yourans>\n"; 
        $xml_output .= "\t</entry>\n"; 
    } 
    
    $xml_output .= "</entries>"; 
    echo $xml_output;
    I can get it to work if I put name,email,testtype,and testnumber variables in the php code but when I take them out, it stops working...this tells me I am not getting the vars from flash to php

    thanks in advance
    Last edited by Beyond Flash; 08-19-2010 at 10:10 PM.
    Beyond Flash
    Your one stop web shop
    http://www.beyondflash.net

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Im not entirely sure what you all got going on.. with the database and etc..etc

    you can try to trace out your data/vars BEFORE you send them.. or even trace out the full URL and check it to make sure it is being sent and in the correct format..then you know if its your PHP script handling or not..etc..

    but if you are trying to send some data to a .php script..and then get some data 'back'... try using the sendAndLoad() method..


    maybe something like this?

    (I havent checked out the php side of things)

    Actionscript Code:
    //project vars
    var userName:String = "someusername";
    var userEmail:String = "someemail";
    var testFormat:String = "MATH";
    var testNumber:String = "1";

    //data arrays for parsing XML
    var serverdate = new Array();
    var servercurrentQuestion = new Array();
    var serveryouranswer = new Array();

    //send data Loadvars object
    var send_data:LoadVars = new LoadVars();
    send_data.username = userName;
    send_data.email = userEmail;
    send_data.testformat = tetFormat;
    send_data.testnumber = testNumber;
    send_data.onLoad = function(success:Boolean) {
        if (success) {
            trace("PHP script found, gathering XML data.");
        } else {
            trace("PHP NOT FOUND");
        }
    };


    //return data XML object
    var return_data:XML = new XML();
    return_data.ignoreWhite = true;
    return_data.onLoad = function(success:Boolean){
        if(!success){
            trace("XML FAILED TO LOAD");
        }else{
            trace("XML LOADED,..PARSING NOW.");
            var myitems = my_xml1.firstChild.childNodes;
            for (var i = 0; i < myitems.length; i++) {
                serverdate[i] = (myitems[i].firstChild.firstChild);//date
                servercurrentQuestion[i] = (myitems[i].firstChild.nextSibling.firstChild);
                serveryouranswer[i] = (myitems[i].firstChild.nextSibling.nextSibling.firstChild);
                M1testDate = serverdate[i];
                M1lastQuestion = servercurrentQuestion[i];
            }
        }
    }


    //make call to send & load the data
    send_data.sendAndLoad("http://www.beyondflash.net/whatever.php",return_data,"POST"); //use an XML object to handle returned XML data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center