-
Notifications
You must be signed in to change notification settings - Fork 0
/
dis.php
99 lines (90 loc) · 2.36 KB
/
dis.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
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
</head>
<body>
<h1 align="center">Discussion Group</h1>
<ul class="list-group" align="center">
<li class="list-group-item list-group-item-info"><a class="item" href="#">Home</a></li>
<li class="list-group-item list-group-item-success"><a class="item" href="create_cat.php">Create a category</a></li>
</ul>
<?php
session_start();
$server = 'localhost';
$username = 'root';
$password = 'password';
$database = 'rangde_cfg';
$conn = mysqli_connect($server, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(!$conn)
{
exit('Error: could not establish database connection');
}
if(!mysqli_select_db($conn,$database))
{
exit('Error: could not select the database');
}
$sql = 'SELECT
id,
cname,
cdesc
FROM
rangde_cfg.categories';
$result = mysqli_query($conn,$sql);
if(!$result)
{
echo 'The categories could not be displayed, please try again later.';
}
else
{
if(mysqli_num_rows($result) == 0)
{
echo 'No categories defined yet.';
}
else
{
//prepare the table
echo '<h2 align="center">Categories</h2><br>';
echo '<table border="1" class="table table-striped">
<tr>
<th>ID</th>
<th>Category name</th>
<th>Category description</th>
</tr>';
$d=0;
while($row = mysqli_fetch_assoc($result))
{
$d++;
if($row['id']>1)
{
echo '<tr>';
$id=$row['id']-2;
echo '<td>'.$id.'</td>';
$_SESSION["cname"] = $row['cname'];
$name=$row['cname'];
$link= "comm".$d.".php";
echo "<td><a href='".$link."'>".$name."</a></td>";
echo '<td>'.$row['cdesc'].'</td>';
echo '</tr>';
}
else
{
echo '<tr>';
$id=$row['id'];
echo '<td>'.$id.'</td>';
$_SESSION["cname"] = $row['cname'];
$name=$row['cname'];
$link= "comm".$d.".php";
echo "<td><a href='".$link."'>".$name."</a></td>";
echo '<td>'.$row['cdesc'].'</td>';
echo '</tr>';
}
}
}
}
?>
</body>
</html>