1
I’m having some problems to insert an ordering in 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 that I am with a problem to be solved, which is to save the order of Drag and Drop system in the database.
The idea is this, the client wants a gallery system that drags the photos from the gallery, so that it is in the order that he determined, drag & drop already does this. I can already recover the ID of each image. Now all I need to do is determine a value like counting from 1 to the amount of images, like: if it has 10 images and the client has done the ordering. I need to list the numbers from 1 to 10, and save these numbers in the table, in the order field, so that when I list the images on the site I order exactly in order.
I don’t know if you can understand, but I’ll show you the excerpt from 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 don’t know guys, if I did it right there, like I wrapped the drag & drop table in a form, to try to recover the values, more unsuccessfully. If anyone can help with this problem, I am most grateful!