Javascript jquerydrag&;删除表行排序不工作
我想制作一个脚本,通过拖放从数据库中排序一些行。这些行显示在一个表中,我拖放行以对它们重新排序。每个tr都有来自数据库的行id。当我拖放一行时,jquery序列化表内容并将其发送到php以保存行位置 行位置未保存在db中可能是什么问题 有行的表格:Javascript jquerydrag&;删除表行排序不工作,javascript,php,jquery,mysql,sql,Javascript,Php,Jquery,Mysql,Sql,我想制作一个脚本,通过拖放从数据库中排序一些行。这些行显示在一个表中,我拖放行以对它们重新排序。每个tr都有来自数据库的行id。当我拖放一行时,jquery序列化表内容并将其发送到php以保存行位置 行位置未保存在db中可能是什么问题 有行的表格: $select_categories = mysqli_query($db_connect, "SELECT `id`, `title` FROM `categories` ORDER BY `category_order` ASC") or die
$select_categories = mysqli_query($db_connect, "SELECT `id`, `title` FROM `categories` ORDER BY `category_order` ASC") or die(mysqli_error());
if(mysqli_num_rows($select_categories) != 0)
{
echo '<table cellpadding="0" cellspacing="0" class="manage_content" id="sort_rows" align="center">';
while($category = mysqli_fetch_assoc($select_categories))
{
echo '
<tr id="row-'.$category['id'].'">
<td width="700"><a href="'.$website_address.'/admin/categories_edit.php?id='.$category['id'].'">'.$category['title'].'</a></td>
<td><a href="'.$website_address.$_SERVER['PHP_SELF'].'?action=delete_content&id='.$category['id'].'" class="delete_content">Delete</a></td>
</tr>
';
}
echo '</table>';
}
AJAX
if(isset($_POST['action']) && $_POST['action'] == 'change_rows_order')
{
$order_no = 1;
foreach($_POST['rows_order'] as $row_id)
{
$update_order = mysqli_query($db_connect, "UPDATE `".clear_tags($_POST['table'])."` SET `".clear_tags($_POST['order'])."` = '".$order_no."' WHERE `id` = '".$row_id."'") or die(mysqli_error());
$order_no++;
}
}
HTML
<table cellpadding="0" cellspacing="0" class="manage_content" id="sort_rows" align="center">
<tr id="row-10">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=10">Editorial</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=10" class="delete_content">Delete</a></td>
</tr>
<tr id="row-11">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=11">Fashion</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=11" class="delete_content">Delete</a></td>
</tr>
<tr id="row-12">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=12">Street Style</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=12" class="delete_content">Delete</a></td>
</tr>
<tr id="row-13">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=13">Portraits</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=13" class="delete_content">Delete</a></td>
</tr>
<tr id="row-14">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=14">Clothing</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=14" class="delete_content">Delete</a></td>
</tr>
</table>
我解决了这个问题。我在这里遵循了教程:这里有太多的未知。您采取了哪些故障排除步骤?@charlietfl我不知道如何将序列化数据传递给AJAX,我认为这就是问题所在。基本上,当我拖放一行时,我希望将包含所有行的数组传递给AJAX,然后将它们的位置保存在db中。应该已经在传递数据了…请在浏览器控制台的“网络”选项卡中检查请求,以查看是什么sent@charlietfl我在JS日志中没有错误。使用PHP是一个问题。我用AJAX发送的净化变量只是一个字符串。我不知道如何将其转换为数组,以便能够在PHP foreach中使用它。这是我拖放时随AJAX发送的变量示例:row[]=10&row[]=11&row[]=12&row[]=14&row[]=13
。如何将其转换为数组?@sorinu26将字符串转义以用于,mysqli\u real\u escape\u string
而不使用任何其他函数是正确的工具。但是,如果您想转义字符串以用于中,那么使用mysqli\u real\u escape\u string
是错误的,因为它不是MySQL字符串文本。
<table cellpadding="0" cellspacing="0" class="manage_content" id="sort_rows" align="center">
<tr id="row-10">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=10">Editorial</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=10" class="delete_content">Delete</a></td>
</tr>
<tr id="row-11">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=11">Fashion</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=11" class="delete_content">Delete</a></td>
</tr>
<tr id="row-12">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=12">Street Style</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=12" class="delete_content">Delete</a></td>
</tr>
<tr id="row-13">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=13">Portraits</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=13" class="delete_content">Delete</a></td>
</tr>
<tr id="row-14">
<td width="700"><a href="http://local.admin.com/admin/categories_edit.php?id=14">Clothing</a></td>
<td><a href="http://local.admin.com/admin/index.php?action=delete_content&id=14" class="delete_content">Delete</a></td>
</tr>
</table>