SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change order of display

    I want to be able to change the order of the display.

    I want the following

    productA move down
    productB move up/move down
    productC move up/move down
    productD move up

    I've seen links like these on forums admin. How can I achieve this ?

  2. #2
    SitePoint Member
    Join Date
    Sep 2003
    Location
    sydney, Australia
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An idea:

    - Have a 'position' field of each product.

    - When move up/down is clicked, swap the 'position' of that product with the 'position' of upper/lower product.

    - Then re-fresh the list of products by doing query to database again, ORDER BY 'position'.

  3. #3
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm,

    How can I swap it ? All of the other product will have to be changed than, wouldn't they?

  4. #4
    SitePoint Member
    Join Date
    Sep 2003
    Location
    sydney, Australia
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No.. just change the 'position' of the 2 products: the one that's being moved up/down, and the product adjacent to it.

    say your product being moved up/down is $product_position.

    roughly like this:
    PHP Code:
    if ($move_up) {

    // set the product position temporarily to 0:
    $query "UPDATE table_name SET position=0 where position=$product_position";

    mysql_query($query);

    // move the product above it downwards:
    $query "UPDATE table_name SET position=$product_position where position=$product_position-1";

    mysql_query($query);

    // and finally, set the position of the product being moved up:
    $query "UPDATE table_name SET position=$product_position-1 where position=0";

    mysql_query($query);


    And do similarly with moving down. But basically, that's it.

    Also you need to consider cases where product being moved up is already in the top of the list (ie. position=1) or where product being moved down is already in the bottom of the list.

    Hope it helps.

  5. #5
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx, I have it working now !


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
  •