-
Notifications
You must be signed in to change notification settings - Fork 2
/
process.php
65 lines (54 loc) · 2.14 KB
/
process.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
<?php
try{
$con = mysqli_connect('localhost', 'root', '', 'employee');
if($_GET["action"]=="list"){
//Count the records
$result = mysqli_query($con,"SELECT COUNT(*) AS RecordCount FROM records;");
$row = mysqli_fetch_array($result);
$recordCount = $row["RecordCount"];
// Get All records from database
$result = mysqli_query($con,"SELECT * FROM records ORDER BY ". $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] .",". $_GET["jtPageSize"] .";");
$rows = array();
while($row = mysqli_fetch_array($result)){
$rows[] = $row;
}
$jTableResult = array();
$jTableResult['Result'] = 'OK';
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
echo json_encode($jTableResult);
}
else if($_GET["action"] == "create"){
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$salary = $_POST["salary"];
//Insert Query
$result = mysqli_query($con,"INSERT INTO records(fname,lname,salary) VALUES ('$fname','$lname','$salary')");
//Get last insert record
$result = mysqli_query($con, "SELECT * FROM records WHERE emp_id = LAST_INSERT_ID();");
$row = mysqli_fetch_array($result);
//Return result to jtable
$jTableResult = array();
$jTableResult["Result"] = "OK";
$jTableResult["Record"] = $row;
echo json_encode($jTableResult);
}
else if($_GET["action"] == "update"){
$result = mysqli_query($con, "UPDATE records SET fname = '". $_POST["fname"] ."',lname = ". $_POST["lname"] ." WHERE emp_id = ". $_POST["emp_id"] .";");
$jTableResult = array();
$jTableResult["Result"] = "OK";
echo json_encode($jTableResult);
// Return result to jTbale
}
else if($_GET["action"] == "delete"){
$result = mysqli_query($con, "DELETE FROM records WHERE emp_id = ". $_POST["emp_id"] .";");
// Return Result to jTable
$jTableResult = array();
$jTableResult["Result"] = "OK";
echo json_encode($jTableResult);
}
mysqli_close($con);
}
catch(Exception $e){
}
?>