Jump to content

Sort data from mysql


eevan79

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/209327-sort-data-from-mysql/
Share on other sites

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

I know that. :D

 

Here is picture (Admin control panel)

001mj.jpg

 

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 :D

 

I hope you understand now, and didnt confuse you :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.