I’ve found this drag and drop script and it’s brilliant but I can’t seem to get it to update the results in the database.
I’ve got this on the page:
<script language="Javascript">
$(document).ready(function() {
// Initialise the table
$('#images').tableDnD({
onDragClass: "drag",
onDrop: function(table, row) {
alert($.tableDnD.serialize());
$.ajax({
type: "POST",
url: "http:/www.domain.com/new_site/admin/ajaxtest.php",
data: "" + $.tableDnD.serialize(),
success: function(html){
}
});
}
});
});
</script>
the alert box does give the correct values, but when I call the ajaxtest.php page nothing happens.
The ajaxtest.php page has this:
<?php
include '../includes/db.php';
$images[] = $_POST['images'];
$i = 0;
if(!empty($images[0])){
foreach($images as $value) {
foreach($value as $row){
$i++;
if($row != 'tHeader'){
$this->Image->set('id', $row);
$this->Image->set('order', $i);
$this->Image->save();
}
}
}
}
$con = mysql_connect($host,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $con);
$sql= sprintf("UPDATE `images` SET `order`='$i' WHERE `id`='$row'");
if (!mysql_query($sql,$con))
mysql_close($con)
?>
I’m pretty sure the problem is with the $images[] = $_POST[‘images’]; but of code, but I’m not sure exactly where and would be extremely grateful for any help.