imi_99 Posted February 25, 2008 Share Posted February 25, 2008 Hello everyone, I am stuck in dealing with a new function never used before. I will explain here what i needed. I have items stored in databases with column "priority". In priority column numbers can be 1,2, 3, 4, 5 ..... Items shows on web page according to this priority. What my objective is write a script in which i can change priority in admin section. e.g if i want to show item no. 5 on number 2 then how i can swap the place and update the prioriteis. Also what if by mistake there are some values repeated, how can i make them unique. thanks Link to comment https://forums.phpfreaks.com/topic/92905-priority-issue/ Share on other sites More sharing options...
imi_99 Posted February 26, 2008 Author Share Posted February 26, 2008 any idea, cant find the solution Link to comment https://forums.phpfreaks.com/topic/92905-priority-issue/#findComment-476831 Share on other sites More sharing options...
DarkerAngel Posted February 26, 2008 Share Posted February 26, 2008 $query = ("SELECT fields FROM table [WHERE field = 'value'] ORDER BY field [DESC or ASC] [liMIT #from, #to ]") items in [] are optional (but remove the [] of you chose to use them) DESC = orders descending ASC = orders asending LIMIT limits the results #from (0 would be first result) #to (Last result) Link to comment https://forums.phpfreaks.com/topic/92905-priority-issue/#findComment-476840 Share on other sites More sharing options...
aschk Posted February 26, 2008 Share Posted February 26, 2008 A simple solution would be to pull all 5 records into PHP, take a tmp copy of the one you want to move, shift all other array members in the specified direction, and then re-insert your tmp copy in the new space, then delete, and reinsert the information into your table. Link to comment https://forums.phpfreaks.com/topic/92905-priority-issue/#findComment-476861 Share on other sites More sharing options...
imi_99 Posted February 26, 2008 Author Share Posted February 26, 2008 My question is different. I dont have any issue in displaying result in ascending or descending order. Suppose I have items showing on website in ascending order. Sometime I have to change the priority display like move item no.3 to no.10. On that reason i created a table with two fields, item_column, priority_column. Items are showing according to what is stored in priority column. Priority column store values like 1,2,3,4... Now there are two issue in priority column. If i want to swap position for item3 to position 7(in priority column) etc. And if by error there are duplicates entires than how will i delete duplicate numbers from priority column. How can overcome such kind of issues. Link to comment https://forums.phpfreaks.com/topic/92905-priority-issue/#findComment-477178 Share on other sites More sharing options...
imi_99 Posted March 1, 2008 Author Share Posted March 1, 2008 Finally i sort out problem by just swaping the values. Like change 3 to 5 and 5 to 3. Then using counter assign all values again from start 1 to end value in case of any mistake. thanks for your suggestions. Link to comment https://forums.phpfreaks.com/topic/92905-priority-issue/#findComment-480991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.