-
Notifications
You must be signed in to change notification settings - Fork 0
/
rating==4.php
executable file
·105 lines (88 loc) · 3.86 KB
/
rating==4.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
<!--
/**
* 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 fundoverview.FundName, Category, FundFamily, Inception, NetAssets, YTD_Return, Yield, Rating, Share_Price, Change_USD, Change_Perc from fundoverview join priceandperformance on fundoverview.FundName = priceandperformance.FundName where Rating > 3 and Rating <5;";
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>
<title>Rating = 5 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" />
<body>
<div class="">
<img class="newappIcon" src="images/newapp-icon.png" />
<h1>
Welcome to <span class="blue"> Cognitive Hub PHP MySQL API</span> on Bluemix!
</h1>
<p class="description">This API allows you to pull data from a MySQL database. <br>
<form action="http://php-mysql-20170915171443054.mybluemix.net/mutualfundrating4api.php">
<input type="submit" value="JSON API ENDPOINT" />
<form action="https://php-mysql-20170915171443054.mybluemix.net">
<input type="submit" value="Return to all mutual funds" />
</form>
<input type="button" class = "mybutton" onclick="window.location = 'init.php';" class="btn" value="(Re-)Create table"></input></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>