-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstocktable.php
61 lines (53 loc) · 1.88 KB
/
stocktable.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
<?php
include_once('db.php');
$sql = "SELECT * FROM stocks ORDER BY sector, name;";
$res = mysqli_query($db, $sql);
?>
<?php date_default_timezone_set("Asia/Kolkata"); ?>
Last updated <?php echo date('d/m/y H:i:s'); ?><br>
<table>
<tr>
<th>Stock Name</th>
<th>Current</th>
<th>Difference</th>
<th>% Change</th>
</tr>
<?php
$sector_last = "";
while($ar = mysqli_fetch_array($res)) {
//array sql table result manipulation to print data
$name = $ar['name'];
$current = $ar['current'];
$difference = intval($ar['difference']);
$percentage = $ar['percentage'];
$sector = $ar['sector'];
if(strcmp($sector,$sector_last) != 0) {
$a = "<tr><td class=\"sector\" colspan=\"4\"><a href=\"detail.php?sector=$sector\">$sector</a></td></tr>\n";
print($a);
$sector_last = $sector;
}
$string = "";
// if loss then inverted red triangle
if($difference >= 0) {
$string = "<tr class=\"persector $sector\">
<td><a href=\"detail.php?sector=$sector#$name\">$name</a></td>
<td>INR $current</td>
<td><span class=\"inverted triangle\">▼</span>INR $difference</td>
<td class=\"loss\">$percentage%</td>
</tr>\n";
}
// else gain then inverted green triangle
else {
$percentage = abs($percentage);
$difference = abs($difference);
$string = "<tr class=\"persector $sector\">
<td><a href=\"detail.php?sector=$sector#$name\">$name</a></td>
<td>INR $current</td>
<td><span class=\"not_inverted triangle\">▲</span>INR $difference</td>
<td class=\"gain\">$percentage%</td>
</tr>\n";
}
print($string);
}
?>
</table>