-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud.php
93 lines (83 loc) · 2.02 KB
/
crud.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
<?php
include 'database.php';
$pdo = Database::connect();
$type = (isset($_GET['type']) ? $_GET['type'] : null);
if ($type == null)
{
$sql = null;
}
elseif ($type == "archive")
{
$sql = 'SELECT * FROM article WHERE is_archive=1 ORDER BY id DESC';
}
elseif ($type == "article")
{
$sql = 'SELECT * FROM article WHERE is_archive=0 ORDER BY id DESC';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="styles/bootstrap.css" rel="stylesheet">
<script src="js/bootstrap.js"></script>
<title></title>
</head>
<body>
<div class="container">
<div class="row">
<h3>The Conspirator CRUD Grid</h3>
</div>
<div class="row">
<p>
<?php
echo'<a href="index.php?page=create&type='.$type.'" class="btn btn-success">Create</a>';
?>
</p>
<?php
if ($sql == null)
{
?>
<div class="alert alert-warning">
<h3>There's nothing here</h3>
</div>
<?php
}
else
{
?>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Date Created</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<?php
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['article_name'] . '</td>';
echo '<td>'. $row['date_created'] . '</td>';
echo '<td>'. $row['category_id'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="index.php?page=read&type='.$type.'&id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn" href="index.php?page=update&type='.$type.'&id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn" href="index.php?page=delete&type='.$type.'&id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
}
Database::disconnect();
?>
</tbody>
</table>
</div>
</div> <!-- /container -->
</body>
</html>