-
need help to loop/repeat text in dynamic text field
I've been working on a site that wants a dash of content management for its biographies page. I've been successful in getting the SQL database to write to the PHP and then Flash reads it in quite well. The loop in PHP works and sends all the data from the table to PHP and then on to Flash.
However, my problem lies in my ability to take one single dynamic text box and punch out the formatting and biographies like so:
Name: Mike Jones
Biography: I come from Oklahama, etc.
Name: Billy Joe
Biography: I come from Illinois, etc.
I have a loop properly set that kicks out the formatting, but only loops (so far) the single variable over and over again. I've tried putting [i] after the "myData.emName[i]" like so, but it returns as undefined. I also need a way of making my while loop terminate properly (right now, you'll see, it has the number 3 just for testing purposes, but there has to be some way of getting it to only print out how many rows there are in the SQL database, etc). I need desperate help before the week (preferably day) is out.
Here is my actionscript code for my file. It's just a test file so it's pretty stripped down:
myData = new LoadVars();
myData.onLoad = function() {
placeData();
}
myData.load("test.php");
placeData = function() {
var i=0;
while (i<3) {
bioBox.htmlText += "<b>Name: </b> + myData.emName1 + "<br><b>Biography: </b>" + myData.desc1 + "<br><br>";
i++;
}
}
-
Maybe try something like this...
Code:
myData = new LoadVars();
myData.onLoad = function() {
placeData();
};
myData.load("test.php");
placeData = function () {
var i = 0;
while (myData["emName"+i] != undefined) {
bioBox.htmlText += "<b>Name: </b>" + myData["emName"+i] + "<br><b>Biography: </b>" + myData["desc"+i] + "<br><br>";
i++;
}
};
-
-
Can you post test.php file you are using?
-
<?php
$dbhost = 'host';
$dbuser = 'user';
$dbpass = 'pass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'database';
mysql_select_db($dbname);
$query = "SELECT employee, bioText, id FROM bio";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo "&emName{$row['id']}={$row['employee']}&desc{$row['id']}={$row['bioText']}";
}
?>
-
What to you get for an output from this trace?
Code:
myData = new LoadVars();
myData.onLoad = function() {
trace(this.toString());
placeData();
};
myData.load("test.php");
placeData = function () {
var i = 0;
while (myData["emName"+i] != undefined) {
bioBox.htmlText += "<b>Name: </b>" + myData["emName"+i] + "<br><b>Biography: </b>" + myData["desc"+i] + "<br><br>";
i++;
}
};
-
It comes back with a bunch of garbage with pieces of the PHP script intermingled like variables and connection strings, etc.
-
Yes, but are you seeing "emName0=" within the output?
Basically the script posted is looking for the variables 'emName0' 'desc0', 'emName1', 'desc1', 'emName2', 'desc2', etc. If the variables aren't there with the sequence numbers this script won't work.
-
my SQL table starts incrementing at 1 so the ID doesn't ever get to 0. This would break up the script, correct?
-
Yes!
Code:
myData = new LoadVars();
myData.onLoad = function() {
placeData();
};
myData.load("test.php");
placeData = function () {
var i = 1;
while (myData["emName"+i] != undefined) {
bioBox.htmlText += "<b>Name: </b>" + myData["emName"+i] + "<br><b>Biography: </b>" + myData["desc"+i] + "<br><br>";
i++;
}
};
-
My friend... it works beautifully. Thank you so very much. If you were here in the Peoria area, I would buy you a drink.
-
help me~!
so Happy to see this post~!
i need it urgent...
May i know....is it possible to click each,then will run"gotoandplay" to specified frame?
I am new in flash and it made me headache!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|