-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathViewUsers.php
More file actions
92 lines (62 loc) · 1.64 KB
/
Copy pathViewUsers.php
File metadata and controls
92 lines (62 loc) · 1.64 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
83
84
85
86
87
88
89
90
91
92
<html>
<head>
<title>Testing</title>
<link href="MyCSS.css" rel="stylesheet">
</head>
<body>
<?php
echo "<table style = 'border: solid 1px black;'>";
echo "<tr><th>ID</th><th>Type </th><th>Name</th></tr>";
class TableRows extends RecursiveIteratorIterator
{
function __construct($you) {
parent::__construct($you, self::LEAVES_ONLY);
}
function current()
{
return "<td style = 'width:15px;border:10x solid black;'>".parent::current()."</td>";
}
function beginChildren()
{
echo "<tr>";
}
function endChildren()
{
echo "</tr>" ."\n";
}
}
$server = "localhost";
$username = "root";
$password = "";
$dbname = "academycity";
try
{
$connection = new PDO("mysql:host=$server;dbname=$dbname", $username, $password); //connection to the database
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo"</br>";
echo"</br>";
echo "Welcome". "<br/>";
echo "<br/>";
echo "<br/>";
$sth = $connection->prepare("SELECT user_id,user_fullname,user_email FROM users"); //a query statement to select fro the database
$sth->execute();
$row = $sth->setFetchMode(PDO::FETCH_ASSOC); //fetch data fro database
foreach(new TableRows(new RecursiveArrayIterator($sth->fetchAll()))as $k=>$v)
{
echo $v; //display the data
}
/*$result = $sth->fetchAll();
print_r($result);*/
}
catch(PDOException $error)
{
echo "Connection Failed : ". $error->getMessage();
}
echo "</table>";
echo "<br/>";
echo "<br/>";
echo "<br/>";
$connection = null; //close the connection
?>
</body>
</html>