-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregate.php
54 lines (46 loc) · 1.44 KB
/
aggregate.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
<?php
//Calculate Number of Tickets, Pass a connection
function countTicketsDB($conn){
$sql = "SELECT COUNT(*) as NumberOfOrders FROM Tickets";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
echo "Total Tickets: " . $row['NumberOfOrders'];
}
//Calculate Number of Buyer for a given seller
function countBuyersDB($conn,$seller_id){
$sql = "SELECT COUNT(*) as NumberOfBuyers FROM Buyers where Buyers.Sellers_ID='$seller_id'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
echo "Total Tickets: " . $row['NumberOfBuyers'];
}
function countSellersDB($conn,$seller_id){
$sql = "SELECT COUNT(*) as NumberOfSellers FROM Sellers";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
echo "Total Tickets: " . $row['NumberOfSellers'];
}
function totalValueSold($conn){
$sql = "select sum(price) as Totals from (Ticket_Type INNER JOIN Tickets ON Tickets.Ticket_Type_ID=Ticket_Type.id)";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
echo "Total Tickets: " . $row['Totals'];
}
/*MySQL Code*/
$servername = "localhost";
$username = "root";
$password = "test";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully!";
echo "<br>";
countTicketsDB($conn);
countBuyersDB($conn, 2);
countSellersDB($conn, 2);
totalValueSold($conn);
$conn->close();
?>