?
Solved

Get result from PHP--HOW???? sendAndLoad

Posted on 2005-04-18
9
Medium Priority
?
211 Views
Last Modified: 2006-11-18
Hi experts, i have a very simple problem, as im new to this so i don't know. Well the thing is, i have flash interface and i have mysqlDB and php. Im calling a php and get the results from the mysql. This is perfect, till here everything works. but now once the result is fetched from the php, how to pass it to Flash, the result is STRING.

my flash code is below :

var c = new LoadVars();
c.namestr = "";  //this is the empty parameter im passing to PHP
c.sendAndLoad("index.php", c, "post");
c.onLoad = showContent;
function showContent(success) {
      if (success) {
            //
            ??
            what should i write here??
            how to get the result string what PHP has got from.
            //
      }
}


AND THE CODE FOR INDEX.PHP IS BELOW: (WORKS PERFECT AND I SEEN THE REsULT)

<?

//--------this is to connect to mysql
$dbcnx = @mysql_connect("localhost", "admin", "mohsin");
if (!$dbcnx) {  echo( "<P>Unable to connect to the database server at this time.</P>" );
      exit();
}

//---------this is to select my Database
mysql_select_db("test", $dbcnx);
if (! @mysql_select_db("test") ) {
        echo( "<P>Unable to locate the table at this time.</P>" );
exit();
}

//-----this is the parameter im passing from flash, im not sure if this line is required or not
$myParam = $HTTP_POST_VARS['namestr'];

//--------here Im writing the select query
$result = mysql_query("SELECT name FROM test");

 //-------this variable will hold the result STRING.
$str="";

while ( $row = mysql_fetch_array($result) ) {
      $str=$str.$row["name"];
      }
      $myParam=$str;   // THIS IS THE RESULT STRING, TO BE PASSED TO FLASH
      echo($myParam);
      //or should it be  echo("namestr=".$myParam);
?>

SO NOW PLEASE TELL ME HOW TO PASS THE RESULT STRING TO FLASH...hOW????
0
Comment
Question by:VBpassion
  • 5
  • 4
9 Comments
 
LVL 27

Expert Comment

by:negatyve
ID: 13808323
====================================
echo("namestr=".$myParam);
// echo("namestr=".$str);

and in flash

function showContent(success) {
     if (success) {
         trace(this.namestr);
     }
}
====================================
you can get the array back to flash with:
====================================
while ( $row = mysql_fetch_array($result) )
{
     $str=$str . "|" .$row["name"];
}

and in flash

function showContent(success) {
     if (success) {
         var names_array = this.namestr.split("|");
     }
}
====================================
0
 
LVL 1

Author Comment

by:VBpassion
ID: 13813651
hi man , nothing works........i did exactly the same as u told...but when i trace in flash, nothing comes..i can't see my result string....pzl tell me
0
 
LVL 1

Author Comment

by:VBpassion
ID: 13813673
i ried to check if the sucess is true or not , and it comes...

function showContent(success) {
      trace("hi");
      if (success) {
            trace(this.namestr);
      }
}

the trace shows "HI"....but not this.namestr......why???. Please get this thing done, as this is the only small hitch stopping me from my project's progress....plz help
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 27

Expert Comment

by:negatyve
ID: 13813768
what does your

echo($myParam);

output?
0
 
LVL 1

Author Comment

by:VBpassion
ID: 13814039
my $myParam =AbrahamJohnClinton
thats the echo what i get .
0
 
LVL 1

Author Comment

by:VBpassion
ID: 13814061
my query returns 3 rows, Abraham , john, clinton.

and then I do

while ( $row = mysql_fetch_array($result) ) {
     $str=$str.$row["name"];
     }
     $myParam=$str;   // THIS IS THE RESULT STRING, TO BE PASSED TO FLASH
     echo($myParam);

SO echo($myParam) = AbrahamJohnClinton

so when it shows me, why in the flash im not able to trace it ...why??????
0
 
LVL 27

Expert Comment

by:negatyve
ID: 13815927
ok, so if you use:

echo("&namestr=" . $myParam . "&");

what does it trace in flash?

 trace(this.namestr);
0
 
LVL 1

Author Comment

by:VBpassion
ID: 13818098
hi dude.......ok i did wat u asked me to

here is the trace of
     echo("&namestr=" . $myParam . "&");      

      ".$myParam."

this is the trace, exactly...with quotes. The trace in flash shows me the above line including quotes.

i guess now it shouldn't be difficult for u pal...plz tell me what is it.?? whats the problem



0
 
LVL 27

Accepted Solution

by:
negatyve earned 200 total points
ID: 13818227
if you are testing your file locally from flash, you should use the complete path to the php page

c.sendAndLoad("http://localhost/your_folder/index.php", c, "post");
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question