-
Notifications
You must be signed in to change notification settings - Fork 1
/
unpopular.php
142 lines (116 loc) · 4.55 KB
/
unpopular.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<html lang="en">
<head>
<meta charset="utf-8">
<title>671BookStore</title>
<link href="style.css" rel="stylesheet">
<script type='text/javascript' src="scripts.js"></script>
</head>
<body onload="showMenu()">
<h1>
671 BookStore
</h1>
<div class = "menu" style="margin-bottom: 2em;">
<center>
<a href=".">Home</a>
<a href="books.php">Books</a>
<a href="search.php">Search</a>
<a id="signin" style='display:none' href="sign_in.php">Sign in</a>
<a id="register" style='display:none' href="register.php">Register</a>
<a id="myaccount" style='display:none' href="myaccount.php">My Account</a>
<a id="admin" style='display:none' href="admin.php">Admin</a>
<a id="signout" style='display:none' onclick="signout()" href="index.php">Sign Out</a>
</center>
</div>
<?php
// ----------------------------------------------------------------------------------------------------
// - Display Errors
// ----------------------------------------------------------------------------------------------------
ini_set('display_errors', 'On');
ini_set('html_errors', 0);
// ----------------------------------------------------------------------------------------------------
// - Error Reporting
// ----------------------------------------------------------------------------------------------------
error_reporting(-1);
// ----------------------------------------------------------------------------------------------------
// - Shutdown Handler
// ----------------------------------------------------------------------------------------------------
function ShutdownHandler()
{
if(@is_array($error = @error_get_last()))
{
return(@call_user_func_array('ErrorHandler', $error));
};
return(TRUE);
};
register_shutdown_function('ShutdownHandler');
// ----------------------------------------------------------------------------------------------------
// - Error Handler
// ----------------------------------------------------------------------------------------------------
function ErrorHandler($type, $message, $file, $line)
{
$_ERRORS = Array(
0x0001 => 'E_ERROR',
0x0002 => 'E_WARNING',
0x0004 => 'E_PARSE',
0x0008 => 'E_NOTICE',
0x0010 => 'E_CORE_ERROR',
0x0020 => 'E_CORE_WARNING',
0x0040 => 'E_COMPILE_ERROR',
0x0080 => 'E_COMPILE_WARNING',
0x0100 => 'E_USER_ERROR',
0x0200 => 'E_USER_WARNING',
0x0400 => 'E_USER_NOTICE',
0x0800 => 'E_STRICT',
0x1000 => 'E_RECOVERABLE_ERROR',
0x2000 => 'E_DEPRECATED',
0x4000 => 'E_USER_DEPRECATED'
);
if(!@is_string($name = @array_search($type, @array_flip($_ERRORS))))
{
$name = 'E_UNKNOWN';
};
return(print(@sprintf("%s Error in file \xBB%s\xAB at line %d: %s\n", $name, @basename($file), $line, $message)));
};
$old_error_handler = set_error_handler("ErrorHandler");
function debug_to_console( $data ) {
$output = $data;
if ( is_array( $output ) )
$output = implode( ',', $output);
echo "<script>console.log( 'Debug Objects: " . $output . "' );</script>";
}
$con = mysqli_connect("dbproject.saadmtsa.club", "root", "password", "dbproject");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "Select b.ISBN, Title, SUM(ifnull(quantity,0)) as stock
From Books as b left join orderitems on b.ISBN=Orderitems.ISBN
Group by b.ISBN
Order by stock ASC
Limit 0, 15;";
$result = mysqli_query($con, $query);
$table = mysqli_fetch_all($result);
$t = 0;
foreach ($table as $row) {
if($t == 0)
{
echo "<table class='responstable'>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Units Sold</th>
</tr>";
$t = 1;
}
echo "<tr>
<td>$row[0]</td>
<td>$row[1]</td>
<td>$row[2]</td>
</tr>";
}
if($t == 1)
echo "</table>";
else
echo "<center><h1>No books are popular</h1></center>";
?>
</body>
</html>