SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Sorting menu-items

    Hi.

    I am working on a creating a small CMS at the moment.
    I have one table that is containing all menu-items, so that the users can build the menu-items themselves by entering "Title" and "Url-location".
    Now I want the users to be able to decide in which order the menu-items are sorted. I guess this is done by adding another integer-field to the menu-table and then sort the menu-items by this field.
    But my question is, how to make a form where the users are able to decide the sorting-order by pressing two input-buttons either "Up" or "Down" and then the sorting-field is updated accordingly?

    Thx in advance. All suggestions are appreciated.

  2. #2
    SitePoint Zealot manoloweb's Avatar
    Join Date
    Aug 2003
    Location
    Mexico
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that you will need to use javascript as the sorting method, and then PHP to update those values in the database.

    I mean, those up and down buttons should "play" with local variables (maybe hidden fields) and the user interface could be a multiple select box.

    Once the user has finished sorting the menu items, you should end up with something like this:

    menuitem[1]=6
    menuitem[2]=2
    menuitem[3]=1
    menuitem[4]=3
    menuitem[5]=4
    menuitem[6]=5

    where the original [index] is actually the row ID for that menu item in mysql, and the value is the order as the user defined it with those up and down buttons.

    When submitted, you could "foreach" that array and update your menu items in the database, like this:

    PHP Code:
    foreach ($_POST["menuitem"] as $mi_k=>$mi_v) {
        
    mysql_query("update menus set sortorder=".$mi_v." where id=".$mi_k);

    Well this is just my opinion on how to do it, now you could ask in the javascript forum for the rest of the recipe.

    ;-)


Bookmarks

Posting Permissions

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