PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Inserting a value in an autoincrement list?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Inserting a value in an autoincrement list?

Réponse
 
LinkBack Outils de la discussion
Vieux 30/10/2007, 17h54   #1
Richard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Inserting a value in an autoincrement list?

Hello,
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
  Réponse avec citation
Vieux 31/10/2007, 09h11   #2
Sebastian Mendel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Inserting a value in an autoincrement list?

Richard schrieb:
> 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



just two queries:

UPDATE `title`
SET `POSTITION` = `POSTITION` + 1
WHERE `POSTITION` > 2;

INSERT ...;

--
Sebastian
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h02.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09438 seconds with 10 queries