我通过基于股票代码的循环的循环从交易API中提取股票数据。这会吐出xml数据,然后我将其解析并输入MySQL数据库以供日后分析。这是我插入数据库的字段示例(我可以添加更多):
$sql = "INSERT into securities (symbol, ask, ask_time, asksz)
VALUES ('$symbol', '$ask', '$ask_time','$asksz')";
我当前的查询提取所有数据并将其列入行,在输入表后输入:
$sql = "SELECT id, symbol, ask, ask_time, asksz FROM securities";
if($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>id</th>";
echo "<th>symbol</th>";
echo "<th>ask</th>";
echo "<th>ask_time</th>";
echo "<th>asksz</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['symbol'] . "</td>";
echo "<td>" . $row['ask'] . "</td>";
echo "<td>" . $row['ask_time'] . "</td>";
echo "<td>" . $row['asksz'] . "</td>";
echo "</tr>";
}
echo "</table>";
有没有办法比较两个独立的股票?例如,构造我的查询以便将这4个字段仅用于'AAPL',然后在同一行中为'GOOG'提取相同的数据?