| Author |
Message |
Syntax-Error

Joined: 05 Nov 2005 Posts: 1
 Local Time: 5:46 am
Status: Offline
|
Posted: 11/5/2005, 6:26 pm Post subject: problem loading mySQL into flash, plz help! |
|
|
I have a dynamic textbox in my flash movie that loads data from a php file, which retrives data from a mySQL database. When the movie loads, I am presented with strange data.
The php file follows:
| PHP: | <?php &text=TEST
<?
mysql_connect("-------","------","---------");
mysql_select_db("mydb");
$test = "I'm a test.";
echo $test;
$dtest = mysql_query("SELECT author FROM sor_tb where ID = 1");
echo $dtest;
?>
Test ?> |
The expected output would be:
TEST
I'm a test.
John Doe (name of author from mySQL table)
Test
But instead I get:
TEST
I'm a test.
Resource id #3
Test
The swf can be viewed HERE
The table was set up correctly, and only has one row, which has an ID of 1. So, I have no idea where "Resource id #3" comes from and why the data isn't showing up. What am I doing wrong? Thanks. |
|
| Back to top |
|
 |
CyanBlue FV Staff

Joined: 24 Jul 2003 Posts: 2012 Location: Chantilly, VA
 Local Time: 7:46 am
Status: Offline
|
Posted: 11/5/2005, 7:03 pm Post subject: |
|
|
Howdy and Welcome...
Well... If I remember correctly(it's been a while for me not to use PHP), the mysql_query() function returns a reference to the result not the result itself... That's why you are seeing that 'Resource id #3' instead of the actual data...
But since you know that you are only getting one record set, you could try this...
| PHP: | <?php $dtest = mysql_query("SELECT author FROM sor_tb where ID = 1 LIMIT 1"); |
_________________
 |
|
| Back to top |
|
 |
aurelius Site Admin

Joined: 24 Jul 2003 Posts: 1769 Location: somewhere in thomistic metaphysics...
 Local Time: 1:46 pm
Status: Offline
|
Posted: 11/6/2005, 8:57 am Post subject: |
|
|
Yep. You need to access the data in the query with some other functions. For example:
| PHP: | <?php // run the query
$result = mysql_query ( $myQuery );
// all records returned by the query are counted by rows,
// so that the first returned record is row 0, the next
// returned record is row 1, and so on. If there is only
// one returned record, then that is row 0.
// get the value of a field name by row
$row = 0;
$fieldname = "author";
$record = mysql_result ( $result, $row, $fieldname );
// display the value in the table's "author" field at returned record row 0
echo $record; |
_________________
www.absconditus.com // experiments in actionscripted graphic design
"There's no point in doing decorative design...
it would just interfere with what I had to say..."
// Scott King
|
|
| Back to top |
|
 |
aurelius Site Admin

Joined: 24 Jul 2003 Posts: 1769 Location: somewhere in thomistic metaphysics...
 Local Time: 1:46 pm
Status: Offline
|
Posted: 11/6/2005, 9:04 am Post subject: |
|
|
| Also, if you're going to be using mysql a lot, it is useful to build yourself a class (or set of functions)which performs all of the above steps. As you can see, just getting the value of a MySQL record takes a few steps, and you don't want to type all of that each time you need a record. It's easier to build a class (or set of functions) which does all those steps for you. Then you can just call the function that does all of that. |
|
| Back to top |
|
 |
D7

Joined: 05 Mar 2006 Posts: 3
 Local Time: 7:46 am
Status: Offline
|
|
| Back to top |
|
 |
|
| View previous topic :: View next topic |