Mikijs Posted May 12, 2008 Report Posted May 12, 2008 Man ir tabula [ id ] [ seciba ] [ vards ] man ir skripts kurs izveido sarakstu 0. vards1 [uz leju] 1. vards2 [uz leju] [uz augsu] 2. vards3 [uz augsu] bet man nedarbojas tas sortings :( ko ta? Kods $up=$_GET[up]; $ids=$_GET[ids]; $data = dbarray(dbquery("SELECT * FROM lasti_kategorijas WHERE seciba='$up'")); $result = dbquery("UPDATE lasti_kategorijas SET seciba=seciba+1 WHERE id='".$data['id']."'"); $result = dbquery("UPDATE lasti_kategorijas SET seciba=seciba-1 WHERE id='$ids'"); } if($_GET[down]){ $down=$_GET[down]; $ids=$_GET[ids]; $data = dbarray(dbquery("SELECT * FROM lasti_kategorijas WHERE seciba='$down'")); $result = dbquery("UPDATE lasti_kategorijas SET seciba=seciba-1 WHERE id='".$data['id']."'"); $result = dbquery("UPDATE lasti_kategorijas SET seciba=seciba+1 WHERE id='".$ids."'"); } $up="<a href='?ids=$db[id]&up=$db[seciba]'><img src='lasti/up.png' border='0px'></a>"; $down="<a href='?ids=$db[id]&down=$db[seciba]'><img src='lasti/down.png' border='0px'></a>";
bubu Posted May 12, 2008 Report Posted May 12, 2008 Kautkādu pus-rakstītu kodu te esi ielicis. Tev seciba lauks vienmēr palielinās par viens? Caurumi nevar būt (1 2 3 6 7 8 ..)? Kā tu izselektē tos saraksta elementus? ORDER BY ir?
Mikijs Posted May 12, 2008 Author Report Posted May 12, 2008 <? if ($_GET[up]) { $up=$_GET[up]; $ids=$_GET[ids]; $data = dbarray(dbquery("SELECT * FROM lasti_kategorijas WHERE seciba='$up'")); $result = dbquery("UPDATE lasti_kategorijas SET seciba=seciba+1 WHERE id='".$data['id']."'"); $result = dbquery("UPDATE lasti_kategorijas SET seciba=seciba-1 WHERE id='$ids'"); } if($_GET[down]){ $down=$_GET[down]; $ids=$_GET[ids]; $data = dbarray(dbquery("SELECT * FROM lasti_kategorijas WHERE seciba='$down'")); $result = dbquery("UPDATE lasti_kategorijas SET seciba=seciba-1 WHERE id='".$data['id']."'"); $result = dbquery("UPDATE lasti_kategorijas SET seciba=seciba+1 WHERE id='".$ids."'"); } $sql=dbquery("select * from lasti_kategorijas order by seciba"); if(!dbrows($sql)) jump("?admin=lasti/veidi"); $i=0; echo "<ul id='sort_list'>"; $rowi=dbrows($sql); while($db=dbarray($sql)){ $i++; $up="<a href='?admin=lasti/veidi&new=5&ids=$db[id]&up=$db[seciba]'><img src='lasti/up.png' border='0px'></a>"; $down="<a href='?admin=lasti/veidi&new=5&ids=$db[id]&down=$db[seciba]'><img src='lasti/down.png' border='0px'></a>"; if($i==1 && $rowi<2) $return="<li>$db[nosaukums]</li>"; elseif($i==1 && $rowi>1) $return="<li>$down $db[nosaukums]</li>"; elseif($i==$rowi && $rowi>2) $return="<li>$up $db[nosaukums]</li>"; else $return="<li>$down $up $db[nosaukums]"; echo $return; } echo "</ul>"; ?>
NiTrino Posted May 13, 2008 Report Posted May 13, 2008 (edited) nosharoshu no savaam f-jam. http://paste.php.lv/7338?lang=php pārlabo tikai manējos db_fetch, db_exec un db_count, man tās standarta funkcijas visur. Edited May 13, 2008 by NiTrino
bubu Posted May 13, 2008 Report Posted May 13, 2008 db_exec ("UPDATE ".$table." SET ".$field." = ".$prev_ordering." WHERE id = ".$id); db_exec ("UPDATE ".$table." SET ".$field." = ".$current_ordering." WHERE id = ".$did); vietā var rakstīt: db_exec ("UPDATE $table SET $field = $current_ordering + $prev_ordering - $field WHERE id IN ($id, $did)"); Par vienu kveriju mazāk.
NiTrino Posted May 13, 2008 Report Posted May 13, 2008 (edited) tnx :) pārbaudīju, strādā. Edited May 13, 2008 by NiTrino
Recommended Posts