View Full Version : Button Hover pulls mysql data into flash
hombr3w311
June 18th, 2007, 11:42 AM
It feels like I've officially searched to the end of the internet looking for some sort of a solution to this issue.
Summary:
I have a real estate site that has been designed fully in flash. In the floorplans section of the site there are 5 buildings that are clickable which display each floor, from there you can click on each individual unit.
Problem:
The issue is that each unit has it's own dynamic data that is contained in a mysql database. There are 7 fields of information for each unit, and approximately 195 units.
I need for each unit to display its respected information in the provided dynamic text boxes when the unit is hovered over. I have a sample working, however the data that is getting pulled is not dynamic, its dummy data i placed in the FLA file. This is how I need it to display: (please click on 'Prices Section') SITE EXAMPLE (http://www.northpointeplaza.com)
Approach:
I've created 7 dynamic text boxes nested into the swf as containers to display the data in. I've also created hover captions that should link the line of code activating the php file to query the mySQL for the respected row of data.
Please advise in this issue as so far it has been a complete waste of time. Thank you in advance,
Andrew
Digitalosophy
June 18th, 2007, 03:55 PM
What's the php output look like, this seems like a very cut and try situation. Post your code.
hombr3w311
June 19th, 2007, 03:04 PM
Here is some PHP code I can use to get it all working,
<?php
//Database Host (usually localhost)
$server = "localhost";
//Your database user name
$user = "";
//Your database password
$pass = "m";
$database = "";
$tableName = "s";
$conn = @mysql_connect($server,$user,$pass);
$database = @mysql_select_db($database,$conn);
$query = @mysql_query("SELECT * FROM $tableName ORDER BY name");
$total_rows = @mysql_num_rows($query);
while($ourData = @mysql_fetch_array($query)){
$id = $ourData["id"];
$name = $ourData["name"];
$age = $ourData["age"];
$country = $ourData["country"];
$counter++;
print("&user_data$counter=$id|$name|$age|$country");
}
print("&total=$total_rows");
?>
What's the php output look like, this seems like a very cut and try situation. Post your code.
So basically I need some AS code for a button that will interact with the PHP and bring in the 1 line mySql data to the FLA.
Thanks again, big time.
Andrew
hombr3w311
June 20th, 2007, 03:04 PM
Does anyone have any ideas on this? Thanks.
Digitalosophy
June 20th, 2007, 03:43 PM
Sorry - don't have PHP here. What I was looking for was an example of the string Flash loads.
i.e. if you were to go to that page directly, exactly what does the screen say.
duncanhall
June 20th, 2007, 04:09 PM
Ok, so you have 195 units. Units are contained within floors, which are contained within buildings.
User clicks on a building -- A building_id is set within Flash
User clicks on a floor within that building -- A floor_id is set within Flash and the user is shown the units on that floor, in that building.
At this point you can now have a php function all set up to select all units based on 2 criteria - building, and floor.
"SELECT * FROM units WHERE building_id='".$FLASH_BUILDING_ID."', floor_id='".$FLASH_FLOOR_ID."'";
You simply need to send two values from flash to your php file, and store the response in a recordset. Then you already have populated all the unit data for that floor, ready to be displayed on hover.
hombr3w311
June 20th, 2007, 04:50 PM
duncanhall - that seems like the most practical way of doing things. The part I am stuck on is the code for the AS to interact with the PHP.
For example, it should be something like: **not actuall AS code, obviously.
on (rollOver) {
"db.php"
building_id = ""
floor_id= """
unit_id= ""
That code pulls the record from the mysql and displays the information in the 7 pre made dynamic fields.
Does that sound about right???
THANKS!
joran420
June 20th, 2007, 04:54 PM
so you sending it with something like this right?(in flash)
it should return it here if you use an onload like i am
[code]
var mySV = new LoadVars()
var myLV = new LoadVars()
myLV.onLoad=fucntion(){
trace(this.user_data)
var answerArray = this.user_data.split("|")
for (i = 0 ; i < answerArray.length; i++){
trace("["+i+"] = "+ answerArray[i])
}
}
mySV.sendAndLoad("http://www.something.com/myPHP.php",myLV)
}
Utech22
June 20th, 2007, 07:33 PM
also:: The contact us need to be validated;
hombr3w311
June 21st, 2007, 05:24 PM
so you sending it with something like this right?(in flash)
it should return it here if you use an onload like i am
[code]
var mySV = new LoadVars()
var myLV = new LoadVars()
myLV.onLoad=fucntion(){
trace(this.user_data)
var answerArray = this.user_data.split("|")
for (i = 0 ; i < answerArray.length; i++){
trace("["+i+"] = "+ answerArray[i])
}
}
mySV.sendAndLoad("http://www.something.com/myPHP.php",myLV)
}
Joran, I see where you are going with this and I am trying to follow. In this AS code, where will the information be loaded to, ex. a textbox? Also I'm not sure what PHP code to use to interact with this AS. Thank you for your time.
Also Utec22, the verification of the email needs to be completed as well, thanks for pointing that out!
Andrew
joran420
June 21st, 2007, 08:02 PM
information is ALWAYS loaded into variables...
sometime people user LoadMovieNum or something(not sure what it is.....) but that command actually sets _root level flash vars and can work well for some senarios however I ALWAYS do the loadVars method
it just returns the info once you have it what you do with it is up to you
in my Example listed
answerArray[0] = $id = $ourData["id"];
answerArray[1] = $name = $ourData["name"];
answerArray[2] = $age = $ourData["age"];
answerArray[3] = $country = $ourData["country"];
so in the onLoad function to set the countrytext
myTextFieldCountry.text = answerArray[3]
[edit] my code assumed you would be using the php you posted
hombr3w311
June 22nd, 2007, 01:10 PM
Joran - I sorta got it working. I took your code and applied to to another tutorial. Now I have the fla accessing the php which is pulling the data from mysql. NOW i want to modify that so instead of the data pulling automatically when the swf is accessed it is called when a button is hovered over. this means the data fields will be blank unless the button is hovering over them. Here is my code I am using:
AS
myData = new LoadVars()
myData.load("test.php") //php line
myData.ref = this
//Fetch data
myData.onLoad = function(succes){
if(succes){
for(var i=0; i<this.cant; i++){
this.ref["Title_txt"+i].htmlText = "<b>"+this["Title"+i]+"</b>"
this.ref["Comments_txt"+i].text = this["Comments"+i]
this.ref["holder_mc"+i].loadMovie(this["Image"+i])
}
} else trace("Error loading data")
}
stop()
PHP
<?php
$connect = mysql_connect("localhost", "****", "****");
mysql_select_db("siteadmin", $connect);
$result = mysql_query("SELECT Title, Comments, Image FROM titles");
$cant = 0;
while($row=mysql_fetch_array($result)){
echo "Title$cant=$row[Title]&Comments$cant=$row[Comments]&Image$cant=$row[Image]&";
$cant++;
}
echo "cant=$cant";
?>
Here is the link to it:
http://www.northpointeplaza.com/test.swf
Thanks again for your help.
hombr3w311
June 25th, 2007, 01:32 PM
I'm just looking for a solution for this annoying issue. Thanks again.
joran420
June 25th, 2007, 02:18 PM
ummmm I dunno
myButton.onRollOver = function(){
myData = new LoadVars()
myData.load("test.php") //php line
myData.ref = this
//Fetch data
myData.onLoad = function(succes){
if(succes){
for(var i=0; i<this.cant; i++){
this.ref["Title_txt"+i].htmlText = "<b>"+this["Title"+i]+"</b>"
this.ref["Comments_txt"+i].text = this["Comments"+i]
this.ref["holder_mc"+i].loadMovie(this["Image"+i])
}
} else trace("Error loading data")
}
}
}
or something like that?
[edit] although really i would pull in all the data at the beginning and just display it on rollOver...otherwise it will take 20 seconds or so for the onload to fire from when you roll over and it will look like nothing happening
hombr3w311
June 26th, 2007, 03:11 PM
OKay here is what I have, it still isn't displaying in flash but it IS pulling when the php file is ran.
PHP CODE
<?PHP
$link = mysql_connect("localhost"," * "," * ");
mysql_select_db(" * ");
$id = $_POST['id'];
$suite = $_POST['suite'];
$dimensions = $_POST['dimensions'];
$use = $_POST['use'];
$status = $_POST['status'];
$price = $_POST['price'];
$downpayment = $_POST['downpayment'];
$monthlypayment = $_POST['monthlypayment'];
$query = 'SELECT * FROM tutorial001_users';
$results = mysql_query($query);
$rows = 0;
while($row = mysql_fetch_assoc($results)) {
echo "ID $row[id] | SUITE = $row[suite] | DIMENSIONS = $row[dimensions] | USE = $row[use] | STATUS = $row[status] | PRICE = $row[price] | DOWN PAYMENT = $row[downpayment] | MONTHLY PAYMENT = $row[monthlypayment]<br>\n";
$rows++; //increment our row count
}
if($result) echo "&writing=Ok&";
mysql_close($link);
?>
And here is the AS for frame 1:
myData = new LoadVars()
myData.ref = this;
myData.onLoad = function(){
if(this.writing=="Ok") {
for(var i=0;i<this.rows;i++){
dynamictext_txt.htmlText = "<b>"+"ID: "+"</b>"+this["id"+i]+"<br>"+"<b>"+"SUITE: "+"</b>"+this["suite"+i]+"<br>";
}
}
else {
gotoAndPlay(_currentframe);
}
}
And now the code for the Button:
on(rollOver){
myDataOut = new LoadVars()
myDataOut.id = "id";
myDataOut.suite = "suite";
myDataOut.sendAndLoad("search.php",myData,"POST")
}
on(rollOut){
dynamictext_txt.htmlText = "";
}
Can someone please tell me what is missing? Thanks.
Andrew
Digitalosophy
June 26th, 2007, 04:08 PM
I'm not sure why it isn't working. But you really shouldn't be sending an loading everytime you rollover a button.
Try this. Make 2 buttons on your stage, name them "btn_0" and "btn_1". This method uses a multidemensional array but it's really easy once you get your data into this array.
Again I ask what your output looks like so I can help you build the orignal array (mine is hard coded obviously.
answerArray = new Array(["Row 1", "Demension 1", "Status 1"], ["Row 2", "Demension 2", "Status 2"]);
for (var i = 0; i<=answerArray.length; i++) {
var btn = this["btn_"+i];
btn.id = i;
btn.onRollOver = function() {
var tempArray = answerArray[this.id];
tempString = tempArray.toString();
var tempString = tempString.split(",");
for (var j = 0; j<tempString.length; j ++) {
// this is where you would
// load this data into the text file
trace(tempString[j]);
}
};
}
hombr3w311
June 26th, 2007, 04:13 PM
Thanks for the reply, here is the output from the db:
http://www.northpointeplaza.com/search.php
That will show you the data I am trying to loadin into flash...
Thanks.
hombr3w311
June 28th, 2007, 11:45 AM
Does anyone have anything that could help with this? If solved, I'll definitely PAY someone for their time.
Thanks
Digitalosophy
June 28th, 2007, 02:17 PM
Well my above code works, there will needs to be a little tweaking on the php end I think and a little more code in Flash.
I should have a little time tonight to work on it, I'm not looking for any money.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.