Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    XML *manual* sorting?

    Hi,

    Is there a way to resort an xml file using a form?

    So say the xml file contains:

    Code:
    <datacell>
    <name>John</name>
    <data>Something..</data>
    </datacell>
    <datacell>
    <name>Doe</name>
    <data>Something..</data>
    </datacell>
    <datacell>
    <name>Donny</name>
    <data>Something..</data>
    </datacell>
    I want this data to be exported to an html form, and then I want to have the ability to re-sort it.

    So for each value in the form I want a side option like move up, or move down.

    Kinda like using weight in mysql.

    I thought of making an array, but im still not sure how to manually sort that either.

    Any ideas?
    Last edited by Iauwak; 04-20-2007 at 12:37 AM.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    have you seen the sort functions in the php manual at php.net
    sort() arsort(), asort(), ksort(), krsort(), natsort(), natcasesort(), rsort(), usort(), array_multisort(), and uksort().

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want the sorting to be manual though, not like alphabetical.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Sorting is such a pain.
    Two questions:
    1. What do you want to sort by? (Data or name)
    2. What version of php are you using?

    Edit
    Oh I see what you mean now. You want to be able to shift elements around based on user defined choices.
    ...
    I'll have to get back to you on that one. Do you want this to be php driven or visual, like an html page? Question #2 still applies
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would like for them to be able to click an up or down button (as in move up, or down) and then have the xml file saved with that change.. or if there is a more efficient way.

    I am running version 5.1.6, upgrading is not an issue.

    Thanks.

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    think you need AJAX for this

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by rafiki View Post
    think you need AJAX for this
    I agree.
    Though its not technically required to provide the dynamic updating, I would recommend at least using a javascript controlled page and then having them update.
    I've been throwing this around a bit too, seeing what would be an efficent way to do it. Problem is, you pretty much always have to disect an xml file, then reconstruct it, every time an item is shifted (which is not really efficient IMO).
    Easier option:
    Construct your XML files to use either an ordering parameter or element for each block of data. Updating an XML file after mearly changing its location digit is probably far more efficient memory wise then reconstructing the file over an over again.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #8
    New Coder
    Join Date
    Apr 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found a way to use an array to move the elements up and down.. it currently would still require reconstruction.. the array can handle multiple changes, but I don't happen to know any ajax of how to make the form update itself... So for now reconstruction may be the only option.

    I can reconstruct the XML files.. but I have no clue where to start with that idea for the move up/down buttons I want.

    Easier option:
    Construct your XML files to use either an ordering parameter or element for each block of data. Updating an XML file after mearly changing its location digit is probably far more efficient memory wise then reconstructing the file over an over again.
    Last edited by Iauwak; 04-21-2007 at 04:12 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
    •