List:General Discussion« Previous MessageNext Message »
From:Richard Date:October 30 2007 4:54pm
Subject:Inserting a value in an autoincrement list?
View as plain text  
I'm programming with PHP+Mysql a CMS system to easily update my site.

I want to have a list of titles to which I can add new ones either at 
the end of the list or in a chosen position so I can choose what order 
they show up in.

The first solution that I thought of was to add one to all of the 
position values heigher than the position I wish to insert the new one 
to. But this would envolve alot of queries and therefore resources.

So now I'm wandering if it is possible to do this directly with mysql.
Here is an example of what I want to do
I will have a table called titles like this :

table : title
    POSTITION            |   TITLE
        1                        |   title joejjeo
        2                        |   title ejuejej
        3                        |   title ekkke
        4                        |   title eueoueo
        5                        |    title eehiehiehop

And I wish to insert :

        3                        |    title inserted

So that titles in positions 3, 4 and 5 become titles 4, 5 and 6

So I would have :

table : title
    POSTITION            |   TITLE
        1                        |   title 1
        2                        |   title 2
        3                        |    title inserted
        4                        |   title 3
        5                        |   title 4
        6                        |    title 5

Is there an easy way to do this with mysql ? and if not what would be 
the best way to achieve this?

Thanks :)
Inserting a value in an autoincrement list?Richard30 Oct
  • Re: Inserting a value in an autoincrement list?Sebastian Mendel31 Oct