Jump to content

Recommended Posts

So im making a php button to click (like an up or down arrow) to re-order a table but first I need a way to re-assign the primary key 'id' that is auto-increment.

 

Heres a quick look at the table:

 

idmediatitlecontenttext

1photoSample item 1http://media-cdn.tripadvisor.com/media/photo-s/00/...Lorem ipsum dolor sit amet, consectetur adipiscing...

2videoSample item 2media/himmler-poznan-large.flvIn quis nisi tellus, ut gravida elit. Sed aliquet,...

 

So anyways see the id?  Its auto increment and primary...  I need a sql statement to switch the two numbers that I can run from php variables.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/195370-swap-two-primary-keys/
Share on other sites

You should be able to run an UPDATE on the primary and auto_increment id, albiet it is generally not recommended, instead it would be recommended to have a separate column for "order" and then order it by that and you can use that to display it.

 

 

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.