forked from annoyingnika/1.homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.php
More file actions
82 lines (55 loc) · 1.86 KB
/
table.php
File metadata and controls
82 lines (55 loc) · 1.86 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
79
80
81
82
<?php
//table.php
//getting our config.php
require_once("../../config.php");
//create connection
$mysql = new mysqli("localhost", $db_username, $db_password, "webpr2016_mertyarba");
//IF THERE IS "?DELETE=ROW_ID" in the url
if (isset ($_GET["delete"])){
echo "Deleting row with id:".$_GET["delete"];
$stmt=$mysql->prepare("UPDATE messages_sample SET deleted=NOW() WHERE id = ?");
echo $mysql->error;
//replace the "?"
$stmt->bind_param("i", $_GET["delete"]);
if($stmt->execute()){
echo "deleted successfully";
}else{
echo $stmt->error;
}
}
$stmt = $mysql->prepare("INSERT INTO homework(location, time, punishment, name)VALUES (?, ?, ?, ?)");
//SQL sentence
$stmt = $mysql->prepare("SELECT id, location, time, punishment, name, created FROM homework WHERE deleted IS NULL ORDER BY created LIMIT 5");
//if error in sentence
echo $mysql->error;
$stmt->bind_result($id, $location, $time, $punishment, $name, $created);
//save
$stmt->execute();
$table_html = "";
$table_html .= "<table>";
//add something to string
$table_html .= "<tr>";
$table_html .= "<tr>";
$table_html .= "<th>ID</th>";
$table_html .= "<th>Location</th>";
$table_html .= "<th>Created</th>";
$table_html .="<th>Deleted</th>";
$table_html .= "</tr>";
//Get Result
while($stmt->fetch()){
//DO SOMETHING FOR EACH ROW
//echo $id."".$message."<br>";
$table_html .= "<tr>"; //start new row
$table_html .= "<td>".$location."</td>"; //add columns
$table_html .= "<td>".$time."</td>";
$table_html .= "<td>".$punishment."</td>";
$table_html .= "<td>".$name."</td>";
$table_html .= "<td>".$created."</td>";
$table_html .= "<td><a href='?delete=".$id."'>x</a></td>";
$table_html .= "<tr>"; //end row
//echo $id."".$message."<br>";
}
$table_html .= "</table>";
echo $table_html;
?>
<a href="APP.php">APP<a/>