Page 1 of 1

[SOLVED] PHP variables and FlashMX

Posted: Mon Jan 10, 2005 11:11 pm
by dreamline
Hi guyz,
I got a little problem with sending variables to flash. I've done some reading and i got the hang of it when there is a constant variable, however if i need to get something from the DB and send that to flash then it doesn't work..

Here a little example of what does work:

Code: Select all

<?php
$var='mymusic.mp3';
$echo("audio=$var&");
?>

Here a little example of what doesn't work: :(

<?php
$var=$dbname . '.mp3';
$echo("audio=$var&");
?>
Anyone got a clue of why i can't use variables from php to flash? I've tried just about everything..

Thanks... :D

Posted: Mon Jan 10, 2005 11:14 pm
by feyd
show some more code please. I'd like to see how $dbname is set, or whatever you are trying to do..

Posted: Mon Jan 10, 2005 11:16 pm
by rehfeld
what is the contents of the variable $dbname?

you might want to look at urlencode()

Posted: Mon Jan 10, 2005 11:48 pm
by dreamline
Hi guyz,
Well i am working on an mp3 player that gets the name of the files from a database, so what happens is that through sql i grab the name from the database and put it in $dbname. So $dbname contains the name of the file to be played.. Let's say the file i wanna play is mymusic.mp3.

The code speaks imho for itself:

If i hard code the name of the file to be played in $var then the music plays perfectly... If i substitute the hardcode for a variable then it won't play at all, not even a sound..

Posted: Mon Jan 10, 2005 11:53 pm
by feyd
the code doesn't speak completely for itself.. I'd like to see how you set $dbname..

What get's output?

Posted: Mon Jan 10, 2005 11:58 pm
by dreamline
Here my sql query:

Code: Select all

<?php
$query="select * from songs where nummer = $nummer";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$dbname=$row&#1111;'filename'];
?>
$dbname now contains 'mymusic' :)

Posted: Tue Jan 11, 2005 12:01 am
by feyd
where's $nummer come from? What's echo'd out?

If "audio=.mp3" is echo'd out, then you likely have an error in your sql or calls.. add debugging outputs to make sure..

Posted: Tue Jan 11, 2005 12:04 am
by dreamline
Ive done that and echo $var on screen.. And $dbname shows me the exact same name as if i hardcode it.. In this case mymusic.mp3. But Flash doesn't pick it up unless i hardcode the name.. And that's weird..

if I use a php variable in the echo command then it just doesn't work.. :(

Even if i do it like this:

Code: Select all

$dbname='mymusic';
echo("audio=' . $dbname . '.mp3&');
The out put is audio=mymusic.mp3& and even then it won't play the sound..

Posted: Tue Jan 11, 2005 12:15 am
by feyd
what does flash say it captures?

Posted: Tue Jan 11, 2005 12:38 am
by dreamline
Can't seem to turn it on.. LOL.. Gotta go to work now.. I'll try that again later... :D Thanks for helping though.. :D

Posted: Tue Jan 11, 2005 10:18 am
by dreamline
K i've generated a textfield in flash and i can see what happens when i use a variable to echo on screen...

If i hardcode the name the textfield in from the file contains indeed mymusic.mp3

However if i wanna print the content dynimacally on screen then the textfield contains undefined..

So basically there's something going wrong when i use variabels to echo the string to send to flash on my screen..

Anyone have an idea how to fix that?

Posted: Tue Jan 11, 2005 1:12 pm
by rehfeld
your just missing something. there should be no difference whether you echo a variable or a hardcoded string.


look at the difference in output between what works and what doesnt. there has to be a difference, otherwise both ways will work.
make sure your not misspelling variables.

Posted: Tue Jan 11, 2005 8:22 pm
by dreamline
I was indeed missing something.. I loaded a php file on startup of the .swf file, but when i user vars in the url everything works smoothly.. I am a n00b when it comes to flash... LOL...

Thanks for pointing me all in the right direction guyz.. :D