# Database grabs with Flash MX04

**URL:** https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214
**Category:** Uncategorized
**Created:** [August 25, 2004, 11:02pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214 "2004-08-25T23:02:02Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![moai](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@moai](https://forum.kirupa.com/u/moai)
#### Post date: [August 25, 2004, 11:02pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/1 "2004-08-25T23:02:02Z")

</div>

Hi.

I’m looking to pull text from a database and display it in various places in Flash. I was also like to be able to format the text with CSS.

What is the best way to do this?  
Its a MySql db, and I’m aiming to use PHP as well since I know it.  
I’ve seen people that create XML docs from PHP, but I’m wondering if it would be worthwhile to do this or not.

Can somone run down the best way to do this?

I guess I could do simple text files as well, but I’m sort of attached to doing the database design.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 25, 2004, 11:05pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/2 "2004-08-25T23:05:51Z")

</div>

Howdy… 🙂

If you do not need to save the result to somewhere else(XML or Text file) then there is absolutely no reason to generate one, unless if you want to slow down the processing speed intentionally…

Just have PHP file output the value from the database that Flash can understand…  
Flash understands the output format of ‘variable1=value1&variable2=value2’… 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 25, 2004, 11:51pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/3 "2004-08-25T23:51:50Z")

</div>

ok,

Would I be able to format the data coming in as well with CSS?  
Also, can you link to an external CSS file from inside Flash?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 25, 2004, 11:59pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/4 "2004-08-25T23:59:27Z")

</div>

Well… It depends on how you define ‘format’… But I’d say leave it up to the Flash for the formatting part since Flash is slow on processing the string data…

As for the CSS, I have no clue since I don’t use FMX 2004…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2004, 12:41am UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/5 "2004-08-26T00:41:07Z")

</div>

Im talking about making part of the text that is getting pulled from the database bold or italic, etc.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2004, 6:38am UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/6 "2004-08-26T06:38:28Z")

</div>

Bold and/or italic doesn’t need CSS, you can do that with html-enabled textareas.  
But yes, you can also use CSS in FMX04, either internally, or by loading the stylesheet.  
Check out the tutorials here and Flash Help, everything is in there.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2004, 9:13am UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/7 "2004-08-26T09:13:29Z")

</div>

Right i knew you could do it with HTML tags, but that seems redundant.

I started trying to pull from my DB in Flash, but it doesnt’ seem to be working.

Can anyone see a problem with this code?

```php

  
  <?php
  //read.php 
  //prints contents of content column where filename = $file
  
  $host = "localhost";
  $user = "flash";
  $pass = " ****";
  $dbName = "flashphp";
  $tableName = "flashText";
  
  
  // Attempt to connect to MySQL server
  
   $link = mysql_connect($host, $user, $pass) or die("fiddlesticks: " . mysql_error());
    mysql_select_db($dbName);
    
    $result = mysql_query("SELECT content FROM $tableName1 WHERE (name=$_GET[file])");
   
    $desiredContent = mysql_fetch_array($result, MYSQL_ASSOC);
  
    mysql_free_result($result);
  
    print "bioText=$desiredContent[bioText]";
  
    mysql_close($link);
  ?>
  

```

That’s the PHP file obviously… and the Actionscript is…

```php

  onClipEvent (load) {
    loadVariables("http:/localhost/bio.php?file=bio", this, "GET");
  }
  

```

The text areas’s variable name is “bioText”.  
The db has 2 fields, “name” and "content"  
So any red flags??

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2004, 1:33pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/8 "2004-08-26T13:33:31Z")

</div>

Uh, I don’t know why you use onClipEvent and loadVariables() in FMX 2004, but try this… Remove that movieClip script and put this into the frame…

```php

bio_lv = new LoadVars();
bio_lv.file = "bio";
bio_lv.onLoad = function(ok)
{
	 if (ok)
	 {
		 trace("Finished loading data from the server...");
		 trace("this.name = " + this.name);
		 trace("this.content = " + this.content);
		 trace("this = " + unescape(this));
	 }
	 else
	 {
		 trace("Problem accessing server...");
	 }
}
bio_lv.sendAndLoad("http:/localhost/bio.php", bio_lv, "POST");

```

and post the trace output if it does not work…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2004, 3:51pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/9 "2004-08-26T15:51:37Z")

</div>

```php
<?php
  //read.php 
  //prints contents of content column where filename = $file
  
  $host = "localhost";
  $user = "flash";
  $pass = " ****";
  $dbName = "flashphp";
  $tableName = "flashText";
  
  
  // Attempt to connect to MySQL server
  
   $link = mysql_connect($host, $user, $pass) or die("fiddlesticks: " . mysql_error($link));
    mysql_select_db($dbName);
    
    $result = mysql_query("SELECT content FROM $tableName1 WHERE name='" . $_GET['file'] . "'", $link) or die ("Query Error: " . mysql_error($link));
	$desiredContent = mysql_fetch_assoc($result);
    print "&bioText=" . $desiredContent['bioText']; //doesn't hurt to just have the amp;  
    mysql_close($link);
  ?> 

```

[AS]bio\_lv = new LoadVars();  
outgoing\_lv = new LoadVars();  
outgoing\_lv.file = “bio”;  
bio\_lv.onLoad = function(success)  
{  
if (success)  
{  
trace(“Finished loading data from the server…”);  
trace("this.name = " + this.name);  
trace("this.content = " + this.content);  
trace("this = " + unescape(this));  
}  
else  
{  
trace(“Problem accessing server…”);  
}  
}  
outgoing\_lv.sendAndLoad(“bio.php”, bio\_lv, “POST”);//use relative paths![/AS]

When having problems like this, tracing functions are your best friend. In flash, you can use trace() or you can list all the variables/objects, in php you can just print to the page. Tracing will help you narrow your problems quickly.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2004, 4:52pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/10 "2004-08-26T16:52:07Z")

</div>

Oh, dumb me… Yeah… It’s got to be sendAndLoad() function… :goatee:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2004, 5:36pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/11 "2004-08-26T17:36:03Z")

</div>

Also, I noticed you are using variable names for your text boxes, but i’d suggest using an instance name and:

```auto
myTextBox.html = true;
myTextBox.htmlText = "<B>your text</B>";

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2004, 6:42pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/12 "2004-08-26T18:42:27Z")

</div>

Ok,  
questions…

1. You’re using $\_Get in PHP and $\_POST in FLash. Isnt that a mistake??
2. Im not getting what you mean by replacing the variable name with an instance and the AS above.
3. Can you comment any more on the AS? There’s a few things I’ve never seen.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2004, 8:01pm UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/13 "2004-08-26T20:01:15Z")

</div>

1. Yes. (see code below)
2. Don’t assign a Variable Name, assign an instance name. Look around the text-box properties and you’ll see what I’m saying.
3. 

```auto
bio_lv = new LoadVars(); //create an object for the returned data.
outgoing_lv = new LoadVars(); //create a Sepereate object for the variables you're passing to the PHP
outgoing_lv.file = "bio"; //assign outgoing variables
//same as sending: ?file=bio
bio_lv.onLoad = function(success){
     if (success){ //success will be true if there was no problem in the accessing the PHP file
	 	_parent.myTextBoxName.html = true; //enables html tags to be placed in the text box
		_parent.myTextBoxName.htmlText = this.bioText; //assigns the value of bioText to the text box 'myTextBoxName'
     }else{
          trace("Problem accessing server...");
     }
}
outgoing_lv.sendAndLoad("bio.php", bio_lv, "POST");//use relative paths!

```

```php
<?php 
  //read.php 
  //prints contents of content column where filename = $file 
   
  $host = "localhost"; 
  $user = "flash"; 
  $pass = " ****"; 
  $dbName = "flashphp"; 
  $tableName = "flashText"; 
   
   
  // Attempt to connect to MySQL server 
   
   $link = mysql_connect($host, $user, $pass) or die("fiddlesticks: " . mysql_error($link)); 
    mysql_select_db($dbName); 
     
    $result = mysql_query("SELECT content FROM $tableName1 WHERE name='" . $_POST['file'] . "'", $link) or die ("Query Error: " . mysql_error($link)); //POST, my bad
    $desiredContent = mysql_fetch_assoc($result); 
    print "&bioText=" . $_POST['bioText']; //doesn't hurt to just have the amp; POST, my bad
    mysql_close($link); 
  ?>

```

All the variables returned from the php page are stored in the LoadVars Object, bio\_lv. For example, if the returning query string or post data is:

```auto
?Name=Norie&Occupation=Pimp&Honesty=false

```

But when loaded into flash using (sendAndLoad or load) produces:

```auto
loadVars_object.Name //will return 'Norie'
loadVars_object.Occupation //will return 'Pimp'
loadVars_object.Honesty //will return 'false'

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 27, 2004, 3:10am UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/14 "2004-08-27T03:10:49Z")

</div>

Alrighty round 3 😛  
hehe  
Still not getting it to work…

1. There’s a syntax error in the SELECT.  
I changed it to

```php

 $result = mysql_query("SELECT content FROM $tableName1 WHERE (name=$_POST[file], $link)";
 

```

btw why is $link in there anyway??

1. 

I’m assuming these

```php

 _parent.myTextBoxName.html = true; //enables html tags to be placed in the text box
_parent.myTextBoxName.htmlText = this.bioText; //assigns the value of bioText to the text box 'myTextBoxName' 

```

should be:

```php

 _root.bioText.html = true; //enables html tags to be placed in the text box
 	   _root.bioText.htmlText = mc_background.bioText; //assigns the value of bioText to the text box 'myTextBoxName'
 

```

Otherwise I dont see anyplace else in the script where the Flash text area is targeted.

1. Is this all to be placed on the root? or on a movieclip with the text area in it?

Thanks for the continued help… i really appreciate it 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 1, 2004, 12:49am UTC](https://forum.kirupa.com/t/database-grabs-with-flash-mx04/62214/15 "2004-09-01T00:49:38Z")

</div>

Post your files.

$link is a pointer to the active connection.  
2)Good Assumption.  
3)Doesn’t matter. Just make sure you are using the correct variable scope.
