Save data to the database with Drag & Drop

1

I'm having some problems inserting a sort into the database, I'm using a Drag and Drop system, which I downloaded on the net and the system works exactly as I need and want.

Only I have a problem to solve, which is to save the system command Drag and Drop in the database.

The idea is this: the client wants a galleries system that drags the photos from the gallery, so that it is in the order he has determined, the drag & drop already does this. I can now retrieve the ID of each image. Now all I need is to determine a type value to make the count from 1 to the amount of images, type: if you have 10 images and the client did the sorting. I need to list the numbers from 1 to 10, and save those numbers in the table, in the order field, so when I list the images on the site I order exactly in order.

I do not know if they could understand, but I'll show the snippet of my code.

<div id="redips-drag">
   <?php
   $order = filter_input_array(INPUT_POST, FILTER_DEFAULT);

   if (isset($order['SelectOrdem']) AND $order['SelectOrdem'] == 'Salvar Ordem'):
      unset($order['SelectOrdem']);
   endif;
   ?>

<form action="" method="post">
   <table style='width:100%;'>
      <colgroup>
         <col width="250"/>
         <col width="250"/>
         <col width="250"/>
         <col width="250"/>
      </colgroup>
      <tbody>
         <tr>
         <?php
         $gbi = 0;
         $Gallery = new Read;
         $Check = new Check;
         $Gallery->ExeRead("ws_posts_gallery", "WHERE post_id = :post", "post={$postid}");

         if ($Gallery->getResult()):    
            $LoopHorizontal = 4;
            $i = 1;

            foreach ($Gallery->getResult() as $gb):
               if ($i < $LoopHorizontal):
                   $gbi++;
                   ?>
                   <td>
                   <div class="redips-drag">
                      <input type="text" name="ordem[]" value="<?= $gbi; ?>">
                      <input type="text" name="id[]" value="<?= $gb->gallery_id; ?>">
                      <?= $Check->Image('../uploads/' . $gb->gallery_image, $gbi, 146, 100); ?><br>
                      <a href="painel.php?exe=produtos/update&postid=<?= $postid; ?>&gbdel=<?= $gb->gallery_id; ?>#gbfoco" class="del btn btn-danger">Deletar</a>
                      </div>
                   </td>

                   <?php elseif ($i = $LoopHorizontal):
                   ?>

                   <td>
                   <div class="redips-drag">
                      <input type="text" name="ordem[]" value="<?= $gbi; ?>">
                      <input type="text" name="id[]" value="<?= $gb->gallery_id; ?>">
                      <?= $Check->Image('../uploads/' . $gb->gallery_image, $gbi, 146, 100); ?><br>
                      <a href="painel.php?exe=produtos/update&postid=<?= $postid; ?>&gbdel=<?= $gb->gallery_id; ?>#gbfoco" class="del btn btn-danger">Deletar</a>
                   </div>
                   </td>
                </tr>
                <tr>
                <?php
                $i = 0;
                endif;
             $i++;
             endforeach;
          endif;
          ?>
          </tr>
       </tbody>
    </table>
    <div class="form-actions">
       <input type="submit" class="btn btn-primary green" value="Salvar Ordem" name="SelectOrdem" />
    </div>
  </form>
</div>

I do not know folks, if I did it right there, I kind of wrapped the drag & drop in a form, to try to recover the values, but to no avail. If anyone can help with this problem, I'm very grateful!

    
asked by anonymous 15.02.2017 / 23:08

1 answer

0

Dude, I already did this as follows: I created a class in a TD for reference via jquery; inside this td I created an input with name array and the key is the id of the product; at the time of clicking the reorder button, I saved the order of the td through a each in jquery, passing the index to the value of the input keyed with the id. at the time of saving, is the order determined by the user

image Array {  1: 0,  15: 1,  95: 2 ... }

example: html:

<td class="imagem" width="50" align="center">
 <img src='/img/imagem.png'>
<input type="hidden" name="imagens[<?= $id; ?>] ?>]" value="">
</td>
 function reordena(){
        $(".imagem").each(function(i){
           $(this).children().val(i);
        });

        $("#form").submit();
    }

php:

  

foreach ($ _ POST ['images'] as $ id = > $ odem) {

     

$ order // here you have the order selected   $ id // here you have the id   }

    
16.02.2017 / 15:47