Jump to content

how to AUTO_INCREMENT 2 colloums not sure if this php or sql


nbbcj

Recommended Posts

how can i have 2 AUTO_INCREMENT colloums ?

 

i need my id column and my position column to Auto increment.

i cant use the id column to set my position as i need to change the val and as i no u cant change ur prim key auto increment column ????

 

so any forts how i can get a drop down list box to show the content of column `position` (in format 1,2,3,4,5,6,7ect ) and auto increment when adding a new project.

 

my idea when adding is to get the form page to read the bottom of the `position` column for the number and then add one and set that val to a read only text field on the project add page.

 

is there an easy or better way to do this and how would one go about doing this ???  as im a noobie but getting there how-tos or code samples will help a lot people and im wanting to learn as well so any good php tutorial sites send them ,my way

 

 

thanks

 

 

Link to comment
Share on other sites

When I need to be able to change the order, I just use the primary ID as a default sorting, that way the value for order can be the same without causing issues:

$queryorder = 'ORDER BY order ASC, id DESC'; // this defaults to new items first compared to other new items
$queryorder = 'ORDER BY order ASC, id ASC'; // this defaults to new items last compared to other new items

This also allows me to use larger numbers for manipulation, in case I want to slip something between two items later on without changing the order value of every item.

 

Just another option.

Link to comment
Share on other sites

In your example query there, you'll need to put backticks around order as it's reserved.

You are correct. I hadn't really thought about that, though. I was just trying to give sample code to try to explain my method.

Oh I know I just wanted to point it out as it's a problem I used to have all the time, using column names like order, desc, etc and then having errors.

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.