I’m trying to create a random quote generator which loads quotes from a MySQL table into a Flash dynamic text field.
I have this PHP code:
<?
$username="my_username";
$password="password";
$database="my_database";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$get_count = "SELECT COUNT(id) FROM facts";
$count_result = mysql_query($get_count)
or die ("Couldn't get count.");
$count = mysql_result($count_result, 0, "COUNT(id)");
srand((double)microtime()*1000000);
$random_id = rand(1, $count);
$get_fact = "SELECT fact FROM facts where id = '$random_id'";
$fact_result = mysql_query($get_fact)
or die ("Couldn't get quote.");
$fact = mysql_result($fact_result, 0, "fact");
$send_fact = "fact=";
$send_fact .= rawurlencode($fact);
echo "$send_fact";
mysql_close();
?>
…which seems to work at least partially as I can see the url-encoded string with the quote if I view the php file.
The tutorial I used to do this suggested the ActionScript:
loadVariables("http://www.theresmoretolifethanshoes.com/quotes.php", fact);
… where my dynamic text box has the instance name of “fact”, but this isn’t working. The box comes up blank.
Any clues as to where I’m going wrong (or suggestions of any more up to date tutorials covering this) would be hugely appreciated.