Jump to content

Recommended Posts

I have a table that has a key, a display_order, and news_headline. I have a php page in a content management form that the business owner uses to add, delete, change & select the top 10 items to display in a news pull-out box on the website. They are in no particular order not date, alphabetic, just arbitrarily chosen by the business owner. My question is, is the a way with just MySQL to update the display_order numbers if the owner deletes rows for display_order 3 and, say 7? I want to renumber all remaining rows to be 1 through n, with n being however many rows are in the table. Can I do this with a MySQL command or do I need to read the entire table into the php script & do an "Update" for each row with the new number from a php variable?

Link to comment
https://forums.phpfreaks.com/topic/46521-resequence-top-10-after-deleting-rows/
Share on other sites

maybe .. just maybe (remember, i'ma mysql noob) this will work..

 

$query = "SELECT * FROM contacts";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$num = $num+1;
mysql_query("INSERT INTO yourtable (id) VALUES ('$num')");

 

you can try it, but.. i have absolutely NO idea if it will work properly

The display order is set by the business owner to show the "important" items at the top of the display list (kind of like a "top 10"), as links to other pages. They are displayed in the order selected by the business owner, not in date, alphabetic, or first-in/first-out, etc. order. So, if there are 15 items on the list, the business owner can re-arrange them to display whatever they deem as "important" at the top of the list.

Before deleting he rows you will need to change the display sequence of the other items. One way is updating all rows after or before the delete. Another way could be assigning an auto generated display order to every item when it is created. The benefit of that is that whenever you delete a row you wouldn't need to rearrange the rest of rows as the other rows would always contain a auto generated sequence display number.

The display order is set by the business owner to show the "important" items at the top of the display list (kind of like a "top 10"), as links to other pages. They are displayed in the order selected by the business owner, not in date, alphabetic, or first-in/first-out, etc. order. So, if there are 15 items on the list, the business owner can re-arrange them to display whatever they deem as "important" at the top of the list.

And why don't you deal with the sequence at this stage?

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.