Jump to content

Recommended Posts

Hi,

 

I have a mysql database containing information I would like to display in my swf.

 

Using php can anyone explain how I might do this?

 

I just need to understand the basics so I can develop it further.

 

Thanks for any help with this.

 

Spencer

As this is more Flash/AS then PHP, I'll give a quick work-flow (if you need more detail on one of them just ask)

PHP

1. Create a PHP script that pulls data from the database and displaying it to the page.

<?php
// Connect
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') OR die(mysql_error());
$userID = 10;
// Query
$query = sprintf("SELECT Username FROM users WHERE ID=%d LIMIT 1", $userID);
$result = mysql_query($query);
//Display
if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

$row = mysql_fetch_assoc($result);
echo $row["Username"];
?>

 

2. Update that script to accept a GET/POST parameter (using $_GET or $_POST)

//$userID = 10; //remove
$userID = (int)$_POST['ID'];//add

2.1 you can create a simple HTML form to test this for POST or edit the URL for testing GET),

or use GET to test then simplely change $_GET to $_POST after testing

 

Flash

3. in your flash app create a action script to load the PHP page. using the parameter (ie 10)

for POST use

userData = new LoadVars();
userData.ID = "10";
returnedData = userData.send("example.php", 0, "POST");

you can change POST to GET (if you want)

returnedData will contain the data from the page. you can set that to whatever you need.

 

Hope that helps

Hi madtechie,

 

I can't seem to get this to work. I have created a flash file with the actionscript you wrote on frame1 of the movie. I get compile errors: 1180: 1120: Access of undefined property userData. and Call to a possibly undefined method LoadVars.

 

I don't actually need to use the whole connect to database bit as I realised that all I actually need to do is pass values from php to and swf so I modified the php to simply <? phpVariable = "test message" ?>

 

I can get php to return info from my database ok so hopefully I should be able to get the principle working a bit more simply.

 

Thanks again for you help.

 

Spencer

I decided to test it, and had a problem anyways I have written a little example of sending and loading data from flash to PHP,

Example you should be able to use this, enter text in top box and click send, and Sigh in ahhhokay it a very basic example, but using the PHP code in the previous post should help with what this lacks

 

Source = Flash & PHP

 

Hope that helps

Thanks for sending that but alas I can't get it to work.  :(

 

I saved all the files to one folder, opened the flash file and exported the swf and then tried to open both of the html files but ie just says : Internet Explorer cannot display the webpage

 

It's probably me just missing something obvious. I am really struggling to work out this problem as a whole (passing variables to flash from php/html). I'm very much a newb at html, as and php. Although I have created some simple stuff.

 

It might help if I explain what I am trying to achieve.

 

Basically I have a table in a mysql db where each row holds information about portfolio items of mine (I'm a digital artist). My aim is to have a generic flash module that can display all the information about any portfolio item one at a time even though they all have different combinations of associated media.

 

So, php will be able construct a page holding lots of different instances of the same flash movie, each displaying a different portfolio item.

 

Therefore I need php to pass information about each row/portfolio item to the flash modules in turn. A user would go to my portfolio site and effectively be presented with a pre-defined list of portfolio items I have picked. The portfolio items are primarly identified by id integers.

 

Does this make sense and does this make your example relevant and do you think I am going down the right lines?

 

Thanks again.

 

Spence

 

 

 

 

here is a simple class file written in AS 3.0

 

package ClientInfo{
import flash.events.*;
import flash.net.*;

public class ClientInfo {
    public var loader:URLLoader
public var  username:*;
	public function ClientInfo() {

		loader=new URLLoader;
		loader.dataFormat=URLLoaderDataFormat.VARIABLES;

		loader.load(new URLRequest("http://www.mydomain.com/6.php"));
		loader.addEventListener(IOErrorEvent.IO_ERROR,IO);


}     


       private function IO (e:IOErrorEvent):void{
	trace("IO ERROR"+e.text);   
   }

	private function handleComplete(event:Event):void{
		loader = URLLoader( event.target );

		 switch(loader.dataFormat) {
                case URLLoaderDataFormat.TEXT :
               
                    break;
                case URLLoaderDataFormat.BINARY :
                    
                    break;
                case URLLoaderDataFormat.VARIABLES :
                  trace("ok");
                    break;
            }



		username=loader.data.user;
		//ip =loader.data.ip;
		//trace(loader.data.user+" refnum = "+loader.data.refnum+" picpath = "+loader.data.refnum);

	   }
	}
}

Hi MadTechie and calmchess,

 

Because I am not a programmer I am a bit slow unfortunately, I realise it's frustrating and appreciate your help. I am struggling with the basics and to be honest I'm not sure where to start with the code and examples you sent over.

 

The obvious way round the problem for me is to start with a very short amount of code which does what I need of it in principle, then I can expand it afterwards.  When I see a larger amount of code with only really a small amount of it demonstrating what I need I get bogged down and confused.

 

I have created a form with php that talks to my database here: http://www.spencercarpenter.co.uk/portfolioAppFiles/simpleForm.php please feel free to have a play with it, the flv movie bit doesn't refresh client side but everything else works how it should. It's not very slick mind as I can't use ajax so most actions cause a full page refresh.

 

Because I know how to retrieve data from the database I know I can create variables that contain all the info I need. I also know that I will be able to loop through a list of IDs and for each one I will be able add a new html table row which contains a flash module template that will be able to display a particular portfolio piece or row from my portfolioItems table in mysql.

 

So logically in my mind all I think I need to know at the moment is how to pass a message/value "test message" from my php doc to a text field in an swf in the simplest possible terms.

 

I do anticipate I will need to create a 'portfolio item' class in AS3 with all the properties pertaining to a portfolio item but other than that I do not understand why I will need to use any other AS classes.

 

Madtechie, your first response is the kind of amount of code I was hoping to have to deal with though if it can't be that simple then I guess that's how it is.

 

Also for reference I generally assume that all AS should be placed at frame one of the flash movie.

 

Again sorry for my lack of knowledge.

 

Spencer

 

What would be ideal is an example like: 'if you upload this swf and php doc to a folder on your webspace, when you go to the php url you will se that the flash module is displaying "test message" which is being driven by the code in the php doc'.

 

It's probably not that simple (like me!).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.