-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_data.php
More file actions
65 lines (56 loc) · 2.29 KB
/
fetch_data.php
File metadata and controls
65 lines (56 loc) · 2.29 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
<?php
header('Content-Type: application/json');
// Database configuration
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "login_system"; // Database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(json_encode(['error' => $conn->connect_error]));
}
// Function to fetch data for a specific company
function fetchCompanyData($conn, $companyName) {
$sql = "
SELECT
SUM(innovation) / (5 * COUNT(DISTINCT user_id)) * 100 AS innovation_percentage,
SUM(team_strength) / (5 * COUNT(DISTINCT user_id)) * 100 AS team_strength_percentage,
SUM(market_scalability) / (5 * COUNT(DISTINCT user_id)) * 100 AS market_scalability_percentage,
SUM(competition_viability) / (5 * COUNT(DISTINCT user_id)) * 100 AS competition_viability_percentage,
SUM(traction_model) / (5 * COUNT(DISTINCT user_id)) * 100 AS traction_model_percentage,
SUM(overall) / (5 * COUNT(DISTINCT user_id)) * 100 AS overall_percentage,
COUNT( CASE WHEN interested_meeting = 'Yes' THEN user_id END) AS interested_meeting_count,
COUNT( CASE WHEN interested_connecting = 'Yes' THEN user_id END) AS interested_connecting_count,
COUNT(DISTINCT user_id) AS unique_users,
SUM(money_invest) AS total_investment
FROM investor_ratings
WHERE company_name = '$companyName';
";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
return $result->fetch_assoc();
} else {
return [
'innovation_percentage' => 0,
'team_strength_percentage' => 0,
'market_scalability_percentage' => 0,
'competition_viability_percentage' => 0,
'traction_model_percentage' => 0,
'overall_percentage' => 0,
'interested_meeting_count' => 0,
'interested_connecting_count' => 0,
'unique_users' => 0,
'total_investment' => 0
];
}
}
// Fetch data for both companies
$data = [
'evigway' => fetchCompanyData($conn, 'Evigway Technologies Private Limited'),
'sparkliv' => fetchCompanyData($conn, 'SparkLiv Private Limited')
];
echo json_encode($data);
$conn->close();
?>