Newbie Question About Getting Quotes from a Database (PHP/MX2004) - long post

Hi all,

This is my first time integrating PHP with Flash, and I’m a bit unsure of myself. I’m using MX2004 and have PHP with MySQL support on a remote server. Overall, I’m trying to get a simple “random quote of the day” thing working.

In the MySQL database, I have a table called quotes. This table has a field called allQuotes. allQuotes has 12 records with random semi-funny stuff that I’ve found on the web.

I have a FLA file with a movie clip with the instance name mcQuote. The movie clip contains one dynamic text field named txtQuote.

On a frame on the main timeline I have the following code:


_root.mcQuote.onLoad = function()
 
{
loadVariables("[https://www.drunkentrolls.com/read.php?file=quotes.php](https://www.drunkentrolls.com/read.php?file=quotes.php)", "_root.mcQuote", "POST");
}

On the server, the file quotes.php contains this code:


 
<?php
 
print "_root.mcQuote.txtQuote=$myQuote";
 
?>

On the server, the file read.php contains this code:


<?php
 
if($file)
 
{
$link = mysql_connect(edited, edited, edited)
	 or die("Failed to connect to database.");
 
$query = "SELECT content FROM files WHERE filename='$quote.php'";
$result = mysql_query($query) 
	 or die("Failed to execute query.");
 
mysql_close($link);
 
$myQuote = mysql_fetch_array($result, MYSQL_ASSOC);
 
mysql_free_result($result);
 
print "txtQuote=$myQuote";
}
?>

Now, if I upload all of this to the server, it’s not going to work because I’m an artist and these programming things never, ever work for me when I first try them. Also, I don’t anticipate getting the php to pick out a random quote and sending it to the flash player anytime this week. I would settle for getting ANY ONE field from this table printed out in the dynamic text file. Any hand-holding would be sooooo appreciated at this point.

this has been by far the most illogical thing i have ever seen.

Congrats !!!

just call a page “quotes.php” from loadVariables

in it :
$link = mysql_connect(edited, edited, edited) or die(“Failed to connect to database.”);

$query = “SELECT myfield FROM allquotes ORDER BY RAND()”;
$result = mysql_query($query) or die(“Failed to execute query.”);
$myQuote = mysql_fetch_array($result, MYSQL_ASSOC);
print “txtQuote=” . $myQuote[myfield];

in flash you will get a variable
_root.txtQuote with the random quote

Woo hoo! I’ll have to collect a prize for the sheer illogic of it all. :wink:

All right, I’ve simplified it (quite) a bit as per your advice. Database has a table called allQuotes with one field named quotes.

Flash file has a dyamic text field named txtQuote on the main timeline, plus this code:


loadVariables("quotes.php", POST);

quotes.php has this code:


<?php
$link = mysql_connect(dbname, username, password) or die("Failed to connect to database.");
$query = "SELECT quotes FROM allQuotes ORDER BY RAND()";
$result = mysql_query($query) or die("Failed to execute query.");
$myQuote = mysql_fetch_array($result, MYSQL_ASSOC);
print "txtQuote=" . $myQuote[quotes];
?>

This still isn’t working, but at least I understand this code a bit better than the tutorial that I was working from originally. :slight_smile: Anything else that I can try?

bump?

check the file locations.

you have used
loadVariables(“quotes.php”, POST);

so it must be referenced via a web url
like http:\…\myflash.swf

or use loadVariables(“http:\…\quotes.php”, POST);

also check the syntax of loadVariables

the PHP code seems to be fine but urlencode the $myQuote[quotes]; before print

also run the quotes.php from a browser to check the output.

then call it from flash

cheers