A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Populate List Box With XML ?

  1. #1
    Moderator enpstudios's Avatar
    Join Date
    Jun 2001
    Location
    Tampa, Fl.
    Posts
    11,282

    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

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  3. #3
    Moderator enpstudios's Avatar
    Join Date
    Jun 2001
    Location
    Tampa, Fl.
    Posts
    11,282
    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);

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  5. #5
    Moderator enpstudios's Avatar
    Join Date
    Jun 2001
    Location
    Tampa, Fl.
    Posts
    11,282
    No I get the same car 18 times !!

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  7. #7
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  8. #8
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    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)?

  9. #9
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Quote 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.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center