Php Ajax、jqueryhtml表重新排序
我需要一些关于使用jquery、ajax和php重新排序html表的帮助。我得到了一些代码,可以在一个列表中运行,但似乎无法在一个表行中运行。这是密码,有人能帮我吗。函数创建表:Php Ajax、jqueryhtml表重新排序,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我需要一些关于使用jquery、ajax和php重新排序html表的帮助。我得到了一些代码,可以在一个列表中运行,但似乎无法在一个表行中运行。这是密码,有人能帮我吗。函数创建表: echo '<table id="test-list" class="gtable sortable">'; echo '<thead>'; echo "<tr>"; echo "<th>Page name&
echo '<table id="test-list" class="gtable sortable">';
echo '<thead>';
echo "<tr>";
echo "<th>Page name</th>";
echo "<th>Edit</th>";
echo "<th>Show</th>";
echo "<th>Delete</th>";
echo "</thead>";
echo "</tr>";
echo "<tbody class='ui-sortable'>";
while($row = mysql_fetch_array($result))
{
$tableid++;
echo "<tr id='listItem_$tableid'>";
echo "<td >" . $row['page_name'] ."</td>";
if ($row['id'] == '1'){
echo "<td>"."<a href='edit_page.php?id=$row[id]'><img src='http://myserver.dev/crm/admin/images/edit.png' /></a></td>";
echo "<td><a href='show_page.php?id=$row[id]'><img class='handle' src='http://myserver.dev/crm/admin/images/arrow-move.png' alt='Move' title='Move' /></a></td>";
}
else {
echo "<td>"."<a href='edit_page.php?id=$row[id]'><img src='http://myserver.dev/crm/admin/images/edit.png' /></a></td>";
echo "<td><a href='show_page.php?id=$row[id]'><img class='move' src='http://myserver.dev/crm/admin/images/arrow-move.png' alt='Move' title='Move' /></a></td>";
echo "<td><a href='delete_pages.php?id=$row[id]'><img src='http://myserver.dev/crm/admin/images/cross.png' /></a>" ."</td>";
}
}
echo "</tr>";
echo "</tbody>";
echo "</table>";
echo';
回声';
回声“;
呼应“页面名称”;
回应“编辑”;
呼应“秀”;
回应“删除”;
回声“;
回声“;
回声“;
while($row=mysql\u fetch\u数组($result))
{
$tableid++;
回声“;
回显“$row['page_name']”;
如果($row['id']='1'){
“回声”;
回声“;
}
否则{
“回声”;
回声“;
“回声”;
}
}
回声“;
回声“;
回声“;
Jquery和Ajax:
<script type="text/javascript">
// When the document is ready set up our sortable with it's inherant function(s)
$(document).ready(function() {
$("#test-list").sortable({
handle : '.handle',
update : function () {
var order = $('#test-list').sortable('serialize');
$("#info").load("process-sortable.php?"+order);
}
});
});
</script>
//文档准备好后,使用其内部函数设置我们的排序表
$(文档).ready(函数(){
$(“#测试列表”)。可排序({
句柄:'.handle',
更新:函数(){
变量顺序=$(“#测试列表”).sortable('serialize');
$(“#info”).load(“process sortable.php?”+order);
}
});
});
process-sortable.php
<?php
/* This is where you would inject your sql into the database
but we're just going to format it and send it back
*/
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("website", $con);
foreach ($_GET['listItem'] as $position => $item) :
$sql=mysql_query("UPDATE pages SET position = $position WHERE id = $item");
endforeach;
print_r ($sql);
?>
如果您每次都加载所有行,那么您可以使用jQuery插件(如TableSorter)完全在客户端完成。这将非常容易实现
你有没有让它工作过?如果你能分享你的解决方案或接受对你有用的答案,那就太好了!:-)