forked from kodiary/php_specials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting.php
More file actions
78 lines (73 loc) · 1.52 KB
/
Copy pathsorting.php
File metadata and controls
78 lines (73 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<title>Drag and Drop Sorting</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="bootstrap/dist/css/bootstrap.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<?php
$link = mysqli_connect("localhost","root","mysql","php_specials");
$q = "SELECT * FROM news_copy ORDER BY display_order ASC";
$result = mysqli_query($link,$q);
if(mysqli_num_rows($result)>0)
{
?>
<table class="table table-striped">
<tr>
<th>Title</th>
<th>Description</th>
<th>Author</th>
</tr>
<tbody class="sortable">
<?php
while($row=mysqli_fetch_object($result))
{
?>
<tr id="<?php echo $row->id;?>">
<td><?php echo $row->title;?></td>
<td><?php echo substr($row->description,0,50).'...';?></td>
<td><?php echo $row->author;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
?>
<script type="text/javascript">
$(function(){
$('.sortable').sortable({
stop:function()
{
var ids = '';
$('.sortable tr').each(function(){
id = $(this).attr('id');
if(ids=='')
{
ids = id;
}
else
{
ids = ids+','+id;
}
})
$.ajax({
url:'save_order.php',
data:'ids='+ids,
type:'post',
success:function()
{
alert('Order saved successfully');
}
})
}
});
});
</script>
</body>
</html>