Re: Drag and Drop with jQuery and PHP
Posted: Fri Aug 14, 2015 9:46 am
It's getting $id from the sorted list. You have id= in your li.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<style>
.magazinetile
{
position: relative;
float: left;
width: 455px;
margin-right: 10px;
margin-bottom: 10px;
position: relative;
background-color: #000000;
}
.magazinetile-content
{
background-color: #ffffff;
text-align: center;
}
.magazinetile-content a
{
padding: 7px;
text-decoration: none;
display: block;
}
.magazinetile img
{
width: 100%;
opacity: 0.85;
}
.magazinetile img:hover
{
opacity: 1.0;
}
.magazinetile img
{
transition: opacity 0.5s;
width: 100%;
}
.magazinetile span
{
width: 30px;
height: 75px;
border: 1px solid #ff0000;
display: inline-block;
float: left;
cursor: move;
}
</style>
$sql = "SELECT * FROM static WHERE section = 'magazine50' ORDER BY priority";
$query = $pdo->prepare($sql);
$query->execute();
$list = $query->fetchAll();
echo "<div id='sortable'>";
foreach ($list as $row) {
$countsquare ++;
echo "<div id='$row[id]' class='magazinetile'";
if (($countsquare % 2) == 0) { echo " style='margin-right: 0px'";}
echo "><a href='$row[url]'><img src='/images/pages/$row[image]' alt='$row[freetext]' /></a>
<div class='magazinetile-content'><a href='$row[url]'>$row[content]</a></div>
<div id='infoi'><span></span><a rel='facebox' href='#edittext$row[id]' class='infoilink'>($row[priority]) EDIT | <a href='/a_magazine&did=$row[id]&u=deletebanner' class='infoilink' onclick=\"javascript:return confirm('Are you sure you want to delete this banner and content?');\">DELETE</a><br/>$row[freetext]</div>
</div>";
if (($countsquare % 2) == 0)
{
echo "<div style='clear: both' /></div>";
}
$catid = NULL;
$subid = NULL;
$id = NULL;
}
echo "<div style='clear: both' /></div></div><br/>";Code: Select all
$(function() {
$('#sortable').sortable({
axis: false,
opacity: 0.7,
handle: 'span',
update: function(event, ui) {
var list_sortable = $(this).sortable('toArray').toString();
// change order in the database using Ajax
$.ajax({
url: 'set_order.php',
type: 'POST',
data: {list_order:list_sortable},
success: function(data) {
//finished
}
});
}
}); // fin sortable
});