-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
141 lines (91 loc) · 2.84 KB
/
index.php
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
require_once('dbconn.php');
$sqlIncomplete = "SELECT id, name, detail, is_completed FROM listitems where is_completed = 'no' ORDER
BY id desc";
$result = mysqli_query($conn, $sqlIncomplete);
//Fetch all imcomplete list items
$incomleteItems = mysqli_fetch_all($result,MYSQLI_ASSOC);
//Get incomplete items
$sqlCompleted = "SELECT id, name, detail, is_completed FROM listitems where is_completed = 'yes' ORDER
BY id desc";
$completeResult = mysqli_query($conn, $sqlCompleted);
//Fetch all complted items
$completeItems = mysqli_fetch_all($completeResult, MYSQLI_ASSOC);
//Free result set
mysqli_free_result($completeResult);
mysqli_free_result($result);
mysqli_close($conn);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Drag and Drop TODO List with PHP MySQL</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<style>
.li_containers{
width: 52%;
float: left;
}
.listitems {
width: 150px;
height: 150px;
padding: 0.5em;
float: left;
margin: 10px 10px 10px 0;
border: 1px solid black;
font-weight: normal;
}
#droppable {
width: 550px;
height: 550px;
padding: 0.5em;
float: right;
margin: 10px;
cursor: pointer;
}
</style>
</head>
<body>
<p><h2 align="center">jQuery Drag and Drop TODO List with PHP MySQL</h2></p>
<div class="li_containers">
<?php foreach ($incomleteItems as $key => $item) { ?>
<div class="ui-widget-content listitems" data-itemid=<?php echo $item['id'] ?> >
<p><strong><?php echo $item['name'] ?></strong></p>
<hr />
<p><?php echo $item['detail'] ?></p>
</div>
<?php } ?>
</div>
<div id="droppable" class="ui-widget-header">
<?php foreach ($completeItems as $key => $citem) { ?>
<div class="listitems" >
<p><strong><?php echo $citem['name'] ?></strong></p>
<hr />
<p><?php echo $citem['detail'] ?></p>
</div>
<?php } ?>
</div>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( ".listitems" ).draggable();
$( "#droppable" ).droppable({
drop: function( event, ui ) {
$(this).addClass( "ui-state-highlight" );
var itemid = ui.draggable.attr('data-itemid')
$.ajax({
method: "POST",
url: "update_item_status.php",
data:{'itemid': itemid},
}).done(function( data ) {
var result = $.parseJSON(data);
});
}
});
});
</script>
</body>
</html>