eevan79 Posted July 30, 2010 Share Posted July 30, 2010 How to sort data from table? Currently its sorted by ID. But I want to add option that admin can sort data (click on up/down link or whatever). Its about forum script and all forums have categories. Forum and categories are in same table. Forum "parent" is ID of category. So i have following sorting: Cat1 [iD1] ->Forum1 [iD2] [PARENT1] ->Forum2 [iD3] [PARENT1] Cat2 [iD4] ->Forum3 [iD5] [PARENT2] ->Forum4 [iD6] [PARENT2] I need to add additional field "sort". On click admin can UPDATE sorting by increasing/decreasing number. But problem is categories and forum are in same table. If I want to move up FORUM1 (ID2) with (for example) "sort" number 2 I must decrease number (-1) and that forum will be with same sort number as category above. Also if I want to move Category up/down it also must move all forums from that category (but that is not big problem). What is best way to solve this? Quote Link to comment Share on other sites More sharing options...
onlyican Posted July 30, 2010 Share Posted July 30, 2010 SELECT fields FROM table ORDER BY fieldname Quote Link to comment Share on other sites More sharing options...
onlyican Posted July 30, 2010 Share Posted July 30, 2010 Sorry, hit the wrong button, the query above is how you do it I would have a link at the columns sending a querystring (GET) method <A href="pagename.php?sortby=name&ord=asc">Name</a> <A href="pagename.php?sortby=Age&ord=asc">Age</a> I do not know your PHP / MySQL Knowledge so let us know if you need more assitance Quote Link to comment Share on other sites More sharing options...
eevan79 Posted July 30, 2010 Author Share Posted July 30, 2010 I know that. Here is picture (Admin control panel) I didnt yet implement code for up/down forums, (there is sample picture). But I want to have "fixed" sorting. When I click on "up" link forum goes up. Thats simple to implement. I'll add another field in mysql "forum_sort" and each forum will have number (similiar as IDs). Default sorting will be by "forum_sort" field. When I create first Category it will get forum_sort 1. Next will have forum_sort 2 etc etc. But when I click on "up" link I must decrease "forum_sort" number so that forum appear one step up in forum list. Problem is when I click "up" on forum with forum_sort 3 that forum will decrease forum_sort on 2 (3-1 = 2 and forum goes up by forum_sorting). But there is also forum with same forum_sort 2 above that forum. Also categories have same forum_sort field. Example: Category1 -->Forum1 -->Forum2 Category2 -->Forum3 -->Forum4 Now Category2 have "forum_sort" 4 and Forum3 have "forum_sort" 5. When I click "up" link on forum3 that forum will have same "forum_sort" as Category2. If I click "up" on Category2 forum2 will move below Category2. Example: Category1 -->Forum1 Category2 -->Forum2 -->Forum3 -->Forum4 When I want to move Forums between categories thats ok. But when I move Category it'll mess up everything I hope you understand now, and didnt confuse you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.