SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: change order of display
-
Oct 4, 2003, 14:05 #1
- 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 ?
-
Oct 4, 2003, 20:32 #2
- 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'.
-
Oct 5, 2003, 03:07 #3
- 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?
-
Oct 5, 2003, 23:12 #4
- 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);
}
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.
-
Oct 6, 2003, 04:09 #5
- Join Date
- Sep 2001
- Location
- Amsterdam
- Posts
- 249
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanx, I have it working now !
Bookmarks