parastsLietotajs Posted June 21, 2008 Report Share Posted June 21, 2008 larbriit :) ir tabulaaa lauks "order" peec kura kaarto ierakstus aptuveni shaadi id | parent_id | name | order "satur" ... 1 | 100 | pirmais | 1 2 | 100 | otrais | 3 3 | 100 | treshais | 2 ... tad, lai apmainiitu vietaaam 2 ierakstus [seciibu apmainiitu], es uzrakstiiju 2 querijus ieksh MsSQL man straadaaja - rakstiiju ieksh mssql, jo tur eertaak paarbaudiit vai pareizi straadaa, phpMyAdmin neerti webaa man ir MySQL UPDATE `tabula` SET `order` = `order`-1 WHERE `id` = 2 shis straadaa. nomaina order par 1 zemaak UPDATE `tabula` SET `order` = `order`+1 WHERE `id` != 2 AND `order` = (SELECT `order` FROM `tabula` WHERE `id` = 2) liidziigs shim uz MsSQL stradaaja id != 2, jo order tagad ir vienaadi `order` = (select...), lai zinaatu kursh "order" jaapalielina par 1 bet MySQL man saka: MySQL teica:#1093 - You can't specify target table 'tabula' for update in FROM clause vai ir kaads racionaalaaks veids kaa apmainiit shos order? protams, es varu uzrakstiit selectu, kas atseviski panjem pashreizeejos "order" un "id" utt... un peec tam uzrakstiit citus update'us vai ariii skriptam padot 2'us "id" un vnk izpildiit pirmo query uz 2 dazaadiem "id" utt utt bet es grib shaadi :) vai arii viismaz zinaat, kapeec nevar shaadi tad nu ko kur pierakstiit lai MySQL aizrijaas un ljauj man izpildiit shaadu query? Link to comment Share on other sites More sharing options...
Kavacky Posted June 21, 2008 Report Share Posted June 21, 2008 Tu paņem PHP pusē visu sakārto, piemēram, visas 10000 vienības to secībā un uzmauc vienkāršu kveriju tiem, kas jāmaina: SET `order`='$ord_X' WHERE `id`='$Y'. Link to comment Share on other sites More sharing options...
bubu Posted June 21, 2008 Report Share Posted June 21, 2008 Atrodi tās abas order kolonnas vērtības kurus gribi apmainīt vietām - $order1 un $order2. Un tad raksti: UPDATE tabula SET order = $order1 + $order2 - order WHERE order IN ($order1, $order2) Link to comment Share on other sites More sharing options...
parastsLietotajs Posted June 21, 2008 Author Report Share Posted June 21, 2008 Atrodi tās abas order kolonnas vērtības kurus gribi apmainīt vietām - $order1 un $order2.Un tad raksti: UPDATE tabula SET order = $order1 + $order2 - order WHERE order IN ($order1, $order2) shis labs :) tad vnk 'id' vietaa es padoshu 1 'order' un otru vnk izdomaashu vai nu +1 vai -1 Link to comment Share on other sites More sharing options...
Recommended Posts