#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Sorting Listbox from XML file:-)


    I'm trying to sort some data drawn from an XML file but i just cant figure out how to do this??
    Can anyone help??

    <?php
    function getOptions($file, $element)
    {
    $xml = simplexml_load_file($file);
    $results = $xml->xpath("//result/$element");
    $results = array_unique($results);
    $options = "<option value=''>- Choose Band Name -</option>\n";
    foreach($results as $res) {
    $options .= "<option ='{$res}'>{$res}</option>\n";
    }
    return $options;
    }
    ?>

    <form method="post" name="Band">
    <select name="bandName">
    <?php echo getOptions('xmldata.xml', 'bandName')?>
    </select>
    <input type="submit" name="btnSubmit" value="Search">
    </form>
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,137
    Rep Power
    1990
    It's quite easy.

    1. Put the values into an array and not directly into the code
    2. Sort that array however it needs to be sorted
    3. Use that array to build the HTML code.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0
    Thankyou,

    Theres always more than one way to skin a cat

IMN logo majestic logo threadwatch logo seochat tools logo