Jump to content

Priority Issue


imi_99

Recommended Posts

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
Share on other sites

$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
Share on other sites

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
Share on other sites

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
Share on other sites

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.