-
Notifications
You must be signed in to change notification settings - Fork 0
/
etf.php
executable file
·113 lines (96 loc) · 4.1 KB
/
etf.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
<!--
/**
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
->
<?php include 'db.php';?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") { //if new message is being added
$cleaned_message = preg_replace('/[^a-zA-Z0-9.\s]/', '', $_POST["message"]); //remove invalid chars from input.
$strsq0 = "INSERT INTO MESSAGES_TABLE ( MESSAGE) VALUES ('" . $cleaned_message . "');"; //query to insert new message
if ($mysqli->query($strsq0)) {
//echo "Insert success!";
} else {
echo "Cannot insert into the data table; check whether the table is created, or the database is active. " . mysqli_error();
}
}
//Query the DB for messages
//$strsql = "select * from MESSAGES_TABLE ORDER BY ID DESC limit 100";
$strsql = "select etf_fundoverview.ETFName, Inception, Bid, Ask, NetAssets, NAV, PE_Ratio, Yield, YTD_Return, Beta, ExpRatio, Share_Price, Change_USD from etf_fundoverview join etf_priceandperformance on etf_fundoverview.ETFName = etf_priceandperformance.ETFName;";
if ($result = $mysqli->query($strsql)) {
// printf("<br>Select returned %d rows.\n", $result->num_rows);
} else {
//Could be many reasons, but most likely the table isn't created yet. init.php will create the table.
echo "<b>Can't query the database, did you <a href = init.php>Create the table</a> yet?</b>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Cognitive Hub API</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="">
<img class="newappIcon" src="images/newapp-icon.png" />
<h1>
Welcome to <span class="blue"> Cognitive Hub PHP MySQL ETF API</span> on Bluemix!
</h1>
<p class="description">This API allows you to pull ETF data from our MySQL database. <br>
<form action="https://php-mysql-20170915171443054.mybluemix.net/rating==5.php">
<input type="submit" value="See 5 star mutual funds" />
</form>
<form action="https://php-mysql-20170915171443054.mybluemix.net/rating==4.php">
<input type="submit" value="See 4 star mutual funds" />
</form>
<form action="https://php-mysql-20170915171443054.mybluemix.net/rating==3.php">
<input type="submit" value="See 3 star mutual funds" />
</form>
<form action="https://php-mysql-20170915171443054.mybluemix.net">
<input type="submit" value="return to all mutual funds" />
</form>
</p>
</br>
<table id='notes' class='records'><tbody>
<?php
echo "<tr>\n";
while ($property = mysqli_fetch_field($result)) {
echo '<th>' . $property->name . "</th>\n"; //the headings
}
echo "</tr>\n";
mysqli_data_seek ( $result, 0 );
if($result->num_rows == 0){ //nothing in the table
echo '<td>Empty!</td>';
}
while ( $row = mysqli_fetch_row ( $result ) ) {
echo "<tr>\n";
for($i = 0; $i < mysqli_num_fields ( $result ); $i ++) {
echo '<td>' . "$row[$i]" . '</td>';
}
echo "</tr>\n";
}
$result->close();
mysqli_close();
?>
<tr>
</tr>
</tbody>
</table>
</div>
</body>
</html>