-
Notifications
You must be signed in to change notification settings - Fork 1
/
stockstable.php
84 lines (76 loc) · 4 KB
/
stockstable.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
<div class="hidden time">
<?php
// time zone is set to Indian Standard Time
date_default_timezone_set('Asia/Kolkata');
// date stamp to be echoed
echo date('Y-m-d H:i:s')."\n";
?>
</div>
<table class="view">
<?php
// make connetion to database
include_once('db.php');
// queries to get list of cryptocurrencies, commodities and stocks
$sql_cryptocurrencies = "SELECT name, current FROM cryptocurrencies ORDER BY name;";
$sql_commodities = "SELECT name, current FROM commodities ORDER BY name;";
$sql_stocks = "SELECT name, sector, current, difference, percentage FROM stocks ORDER BY name;";
?>
<tr class="sector"><td colspan="4" class="sector">Cryptocurrencies</td></tr>
<?php
// from list of cryptocurrencies and their live prices make table rows
$res = mysqli_query($db, $sql_cryptocurrencies);
if(mysqli_num_rows($res) == 0) {
$str = '<tr class="stock"><td class="name" colspan="4">No Cryptocurrencies Available.</td></tr>';
echo $str."\n";
}
while($ar = mysqli_fetch_array($res)) {
$name = $ar['name'];
$current = $ar['current'];
$str = '<tr class="stock" id="'.$name.'" onclick="document.location = \'/details.php#'.$name.'\'"><td class="name">'.$name.'</td><td class="current" colspan="3">₹'.$current.'</td></tr>';
echo $str."\n";
}
?>
<tr class="sector"><td colspan="4" class="sector">Commodities</td></tr>
<?php
// from list of commodities and their live prices make table rows
$res = mysqli_query($db, $sql_commodities);
if(mysqli_num_rows($res) == 0) {
$str = '<tr class="stock"><td class="name" colspan="4">No Commodities Available.</td></tr>';
echo $str."\n";
}
while($ar = mysqli_fetch_array($res)) {
$name = $ar['name'];
$current = $ar['current'];
$str = '<tr class="stock" id="'.$name.'" onclick="document.location = \'/details.php#'.$name.'\'"><td class="name">'.$name.'</td><td class="current" colspan="3">₹'.$current.'</td></tr>';
echo $str."\n";
}
?>
<tr class="sector"><td colspan="4" class="sector">Securities</td></tr>
<?php
// from list of stocks and their live prices, difference, percentage make table rows
$res = mysqli_query($db, $sql_stocks);
if(mysqli_num_rows($res) == 0) {
$str = '<tr class="stock"><td class="name" colspan="4">No Securities Available.</td></tr>';
echo $str."\n";
}
while($ar = mysqli_fetch_array($res)) {
$name = $ar['name'];
$sector = $ar['sector'];
$current = $ar['current'];
$difference = $ar['difference'];
$percentage = $ar['percentage'];
$str = '';
// in case of negative difference use all conventions of green, high
if($difference < 0) {
$difference = -$difference;
$percentage = -$percentage;
$str = '<tr class="stock" id="'.$name.'" onclick="document.location = \'/details.php#'.$name.'\'"><td class="name">'.$name.'<br><small>'.$sector.'</small></td><td class="current">₹'.$current.'</td><td class="difference"><span class="not_inverted triangle">▲</span> ₹'.$difference.'</td><td class="percentage high">'.$percentage.'%</td></tr>';
}
// in case of positive difference use all conventions of red, low
else {
$str = '<tr class="stock" id="'.$name.'" onclick="document.location = \'/details.php#'.$name.'\'"><td class="name">'.$name.'<br><small>'.$sector.'</small></td><td class="current">₹'.$current.'</td><td class="difference"><span class="inverted triangle">▼</span> ₹'.$difference.'</td><td class="percentage low">'.$percentage.'%</td></tr>';
}
echo $str."\n";
}
?>
</table>