-
Moderator
Populate List Box With XML ?
I need to populate a listbox using an XML file written by PHP, after it pulls data from a MySQL DB.
Here is the structure of my PHP file:
Code:
<?php
$link = mysql_connect(myserver,'myusername,'mypassword');
mysql_select_db("myDatabase");
$query = 'SELECT * FROM vehicle_options';
$results = mysql_query($query);
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n";
echo "<options>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<item>\n";
echo "<Year>" . $line["year"] . "</Year>\n";
echo "<Make>" . $line["make"] . "</Make>\n";
echo "<Model>" . $line["model"] . "</Model>\n";
echo "<Price>" . $line["price"] . "</Price>\n";
echo "<Body>" . $line["body_style"] . "</Body>\n";
echo "<Mileage>" . $line["mileage"] . "</Mileage>\n";
echo "<Exterior_Color>" . $line["ext_color"] . "</Exterior_Color>\n";
echo "<Interior_Color>" . $line["int_color"] . "</Interior_Color>\n";
echo "<Engine>" . $line["engine"] . "</Engine>\n";
echo "<Transmission>" . $line["transmission"] . "</Transmission>\n";
echo "<Drive_Type>" . $line["drive_type"] . "</Drive_Type>\n";
echo "<Fuel_Type>" . $line["fuel_type"] . "</Fuel_Type>\n";
echo "<Stereo>" . $line["stereo"] . "</Stereo>\n";
echo "<Doors>" . $line["doors"] . "</Doors>\n";
echo "<Stock_No>" . $line["stock_no"] . "</Stock_No>\n";
echo "<VIN>" . $line["vin"] . "</VIN>\n";
echo "<Comments>" . $line["comments"] . "</Comments>\n";
echo "<Features>" . $line["features"] . "</Features>\n";
echo "</item>\n";
}
echo "</options>\n";
mysql_close($link);
?>
What I want to do is use the Year in the List Box and have all the other fields load in and populate dynamic text fields upon choosing the year in the List Box
-
Senior Member
I would create one variable only for the year and one variable, which holds the whole XML file instead of returning individual nodes to Flash. Then in your flash movie you can use
myList.addItem ({label:myYear, data:myXML});
- The right of the People to create Flash movies shall not be infringed. -
-
Moderator
Ok, I tried that and it helps
But, it only pulls 1 entry from the DB not all of them.
Right now we have 2 cars in the DB it is only showing the first one.
Code:
var theXML:XML = new XML();
theXML.ignoreWhite = true;
theXML.onLoad = function() {
var nodes = this.firstChild.firstChild.childNodes;
var myTitle = nodes[0].firstChild.nodeValue;
var myFeatures = 5;
theList.addItem ({label:myTitle, data:myFeatures});
}
theXML.load("http://www.elitemotorsoftampa.com/vehicles2.php");
function change(evt){
trace(evt.target.selectedItem.data);
}
theList.addEventListener("change", this);
-
Senior Member
When you do a trace in Flash, do you get both cars?
- The right of the People to create Flash movies shall not be infringed. -
-
Moderator
No I get the same car 18 times !!
-
Senior Member
When I do this I do it very differently. I create one XML file:
while($line = mysql_fetch_assoc($results)) {
echo $myResult = . "<Year>" . $line["year"] . "</Ye......] . "</Features>";
}
and in the Flash file I get the XML strings using Loadvars. Inside onLoad I create a new XML file:
var myXML:XML = new XML("<options>" +this.myResult+"<options/>");
then I parse the XML file.
Don't know it helps. I am also currently working on something similar.
- The right of the People to create Flash movies shall not be infringed. -
-
Senior Member
Wrong syntax should be this:
$myResult .=
Here is the important part of a file I recently wrote. I then select out everything in Flash.
PHP Code:
$xmlNodes = "";
//
//we loop through the rows...
//
while($row = mysql_fetch_array($result))
{
$id = $row['id'];
$name = $row['name'];
$subitem1 = $row['subitem1'];
$haircolor = $row['haircolor'];
$age = $row['age'];
$phone = $row['phone'];
$htmlUrl = $row['htmlUrl'];
$pic = $row['pic'];
$myUrl = $row['myUrl'];
//
// comparing strings
//
//
//we store the data as an XML node.
//
$xmlNodes .= "<item id=\"$id\" name=\"$name\" myUrl=\"$myUrl\" htmlUrl=\"$htmlUrl\" pic=\"$pic\"><p><h1>$name</h1><ul><li>age: $age</li><li>hair color: $haircolor</li><li>phone: $phone</li></ul></p></item>";
}
echo "&myResult=" . urlencode($xmlNodes);
- The right of the People to create Flash movies shall not be infringed. -
-
up to my .as in code
Hows this going? Working now?
This example data Estudio?...have an SQL dump if so (it would save time making an exact example)?
I need to populate a listbox using an XML file written by PHP
Also...that line can be interpreted two ways. You mean you actually need to write an XML file and then read it or will inline XML suffice (echoed return saving a step)?
-
Flashmatics
Originally Posted by estudioworks
Ok, I tried that and it helps
But, it only pulls 1 entry from the DB not all of them.
Right now we have 2 cars in the DB it is only showing the first one.
(unless I've totally misunderstood the question)
Thats because you have no loop to iterate through the results returned and are hardcoding with nodes[0].. when php returns the results it will not return it record by record... it will return all of them at once..
put a simple trace to see this
Code:
theXML.onLoad = function() {
trace(this);
}
hope that helps
Last edited by silentweed; 06-03-2007 at 08:06 AM.
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
|