ziedinjsh Posted September 26, 2014 Report Share Posted September 26, 2014 Sveiki! Es te cīnos un un īsti netieku skaidrībā! no datubāzes izvad bildes: <ul id="photolist"> <?php if ($result = $db->query("select * from photos where cat='kids' order by aid desc")){ if ($result->num_rows > 0){ while ($data = $result->fetch_array()){ ?> <li class="ui-state-default" id="photo_<?php echo $data['pid']; ?>"><img src="../photos/300/<?php echo $data['name'];?>"/></li> <?php } } } ?> <div class="fix"></div> </ul> jQuery: jQuery(function(){ jQuery( "#photolist" ).sortable({ update: function(event, ui){ jQuery.post('save.php?w=sortable', { photos: jQuery('#photolist').sortable('serialize') }, function(re){ console.log(re); }); } }); jQuery( "#photolist" ).disableSelection(); }); php: if($w=='sortable'){ $photos = parse_str($_POST['photos'], $photoOrder); foreach ($photoOrder['photos'] as $key => $value) { $update = "update photos set sort='$key' where pid='$value'"; $updated = mysqli_query($db,$update) or die("Error: ".mysqli_error($db)); if (!$updated) { echo 'error'; } } } Pārvietojot bildi console.log parād šo: <br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/ebphotog/public_html/adm/save.php</b> on line <b>168</b><br /> Kas tur pa vainu? P.S. Paldies jau iepriekš! Quote Link to comment Share on other sites More sharing options...
Kasspars Posted September 26, 2014 Report Share Posted September 26, 2014 Vaina tāda, ka foreacham tiek padots arguments, kas nav masīvs (vai kāds cits iterējams tips), ko arī tev kļūdas paziņojums pasaka! Ver vaļā save.php 166 līniju un ar var_dump skaties kāds ir $_POST['photos'] mainīgais un kāpēc viņš netiek pārtaisīts var masīvu Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 26, 2014 Author Report Share Posted September 26, 2014 Viņš atgriež string(0) "" Quote Link to comment Share on other sites More sharing options...
indoom Posted September 26, 2014 Report Share Posted September 26, 2014 (edited) Visticamāk jau vajag $photoOrder['photo'] (jo id="photo_pid") forīčā ne $photoOrder['photos'] Edited September 26, 2014 by indoom Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 26, 2014 Author Report Share Posted September 26, 2014 Labi, paldies, strādā tagad, bet kā tagad izvadīt lai viņš rādā tā kā ir sakārtots?šobrīd man ir šādi: <ul id="photolist"> <?php if ($result = $db->query("select * from photos where cat='kids' order by sort asc")){ if ($result->num_rows > 0){ while ($data = $result->fetch_array()){ ?> <li class="ui-state-default" id="<?php echo $data['pid']; ?>"><img src="../photos/300/<?php echo $data['name'];?>"/></li> <?php } } } ?> <div class="fix"></div> </ul> Quote Link to comment Share on other sites More sharing options...
jurchiks Posted September 26, 2014 Report Share Posted September 26, 2014 Bet viņš tak jau rāda tā, kā ir sakārtots: >order by sort asc Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 26, 2014 Author Report Share Posted September 26, 2014 jā, bet lapā pārvietotjot bildi un refrešojot lapu.. nav tā kā jābūt Quote Link to comment Share on other sites More sharing options...
jurchiks Posted September 26, 2014 Report Share Posted September 26, 2014 Nu tad kaut kas netiek pareizi apdeitots, kad tiek pārvietota bilde. Salīdzini $photoOrder datus ar to, kas tiek izvadīts lapā pēc refresh. Quote Link to comment Share on other sites More sharing options...
Kasspars Posted September 26, 2014 Report Share Posted September 26, 2014 paskaties kādi izskatās update queries, tad radīsies skaidrība Bet nu jocīgi, pats uzraksti kodu, bet nesaproti kā tas darbojas Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 26, 2014 Author Report Share Posted September 26, 2014 es īsti neuzrakstīju, meklēju googlē, kas ir ar update query? Quote Link to comment Share on other sites More sharing options...
jurchiks Posted September 26, 2014 Report Share Posted September 26, 2014 (edited) Update kverijā nevajadzētu būt problēmai. Nesmuki, protams, ka tu hardkodē variabļus, tas ir ļoti viegli eksploitojams, bet tehniski kverijs nav nepareizs. Vienīgi pid vērtībai nevajadzētu būt pēdiņās. Tu salīdzināji ar AJAX aizsūtītos datus ar lapas output pēc refresh? Edited September 26, 2014 by jurchiks Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 26, 2014 Author Report Share Posted September 26, 2014 pff.. Tagad meģinu to izdarīt, bet īsti nezinu kā Quote Link to comment Share on other sites More sharing options...
Kasspars Posted September 26, 2014 Report Share Posted September 26, 2014 Update query ir šitais $update = "update photos set sort='$key' where pid='$value'"; Paskatie kādas vērtības ir mainīgajam $key un $value Iespējams, ka tu esi sajaucis vietām un vajag būt šitā $update = "update photos set sort='$value' where pid='$key'"; Quote Link to comment Share on other sites More sharing options...
Kasspars Posted September 26, 2014 Report Share Posted September 26, 2014 (edited) Ja kaut kas nedarbojas ir jāskatās kādi dati nāk iekšā! Tas saucas debug/atkļūdošana. var_dump($mainigais) būs tavs labākais draugs. Skaties, kur ienāk nepareizi dati Edited September 26, 2014 by Kasspars Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 26, 2014 Author Report Share Posted September 26, 2014 man liekas, ka šobrīd vispār nekas nepadeitojas Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.