Jump to content

Recommended Posts

You would need to save the ids with their placement in a user preference table.  Then you would join the two tables and do something like:

 

items is your table

 

prefs has:  id  placement  user

 

SELECT * from items, prefs WHERE items.id = prefs.id AND prefs.user = something ORDER by placement

 

So it would look something like this:

id   placement
1    1
4    2
5    3
6    4
7    5
8    6
9    7
10   8
2    9
3    10

 

There might be an easier way with a subquery but I think this is pretty standard.

you can order your table with FIND_IN_SET() function

 

SELECT ... FROM ... WHERE .... ORDER BY FIND_IN_SET(id, '1,4,5,6,7,8,9,10,2,3')

 

Good advice.  However, you still need to store '1,4,5,6,7,8,9,10,2,3' somewhere.  Maybe in a session, but then if they log out and back in they must reorder.

I think it will be good idea to save the order in cookies and don't delete them while they logout. This way when users logback they will find there preferred order.

Unless they want to login from another computer or browser.

you can order your table with FIND_IN_SET() function

 

SELECT ... FROM ... WHERE .... ORDER BY FIND_IN_SET(id, '1,4,5,6,7,8,9,10,2,3')

 

Just a note on this:

 

SELECT book_id, book, book_display FROM books WHERE book_status = 'active' ORDER BY FIND_IN_SET(book_id, '13,4,5,6,7,8,9,10,2,3' ) LIMIT 0 , 30

 

this is returning a strange set, the book_id it is returning are (in order given back):  1,12,11,13,4,5,6,7,8,9,10,2,3

 

To get the proper result I had to provide all 13 book ids, this returned them in the proper order. Hopefully that will help someone else.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.