Jump to content
php.lv forumi

palīdziet saprast kā pareizi pārvietot pa order


EdgarsK

Recommended Posts

Sveiki,

 

Mana tabula: id,title,my_order

Ieraksti:

----------------------------

1|Cooler|1

2|Divide|2

3|Clock|3

 

Vēlos nomainīt Id 2 ar id 3

tātad man būtu jādara sekojoši ?

 

update tabula set my_order=my_order+1 where my_order=2
update tabula set my_order=my_order-1 where id=3

 

un otrādi ?

 

Šobrīd izmantoju šo, bet nesaprotu kapēc man vislaik my_order aiziet pa nullem...

Link to comment
Share on other sites

Grūti pateikt, ko tu vēlies, tad tu prasi vienu, kverijā atkal tu gribi nomainīt kaut ko citu... No visa izrietošā es saprotu, ka tu vēlies nomainīt abas vērtības (id, my_order), tad kverijam vajadzētu šādam darboties.

UPDATE tabula SET my_order=my_order+1, id=id+1 WHERE title='Divide'
UPDATE tabula SET my_order=my_order-1, id=id-1 WHERE title='Clock'

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...