【发布时间】:2013-07-03 04:03:08
【问题描述】:
我很难弄清楚我在这里做什么。让我先解释一下我正在尝试做什么以及到目前为止我正在做什么。
我有什么:
到目前为止,我拥有从雅虎获取数据以填充搜索的方式。这是一个简单的表格,要求访问者输入一个符号,然后会吐出报价信息。
我的目标:
如果股票代码是我掌握的信息,我正在尝试关联我的数据库以显示我的数据库信息。因此,假设访问者将股票代码“hig”输入到我想将表称为“stockpicks”的表格中,以查看“symbol”列中是否存在匹配项。如果是这种情况,我想从其他列(例如“注释”)中输出该表中的其他特定数据。
这里是活动样本:http://www.stocksandstocks.com/stock-quotes.php 我似乎无法弄清楚两者之间的关系以及如何正确处理。以下是我目前所拥有的。
<?php
error_reporting(E_ALL ^ E_NOTICE); //this is for debugging, remove if you dont need anymore
ini_set("display_errors", 1); //this is for debugging, remove if you dont need anymore
$searchoutput = "";
$ticker = "goog";
if (isset($_POST['get_quote'])) {
$ticker = $_POST['ticker'];
}
$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$ticker&f=sl1d1t1c1ohgv&e=.csv", "r");
$quote = fread($open, 1000);
fclose($open);
$quote = str_replace("\"", "", $quote);
$quote = explode(",", $quote);
$quote_0 = ($quote[0]);
$quote_1 = ($quote[1]);
$quote_2 = ($quote[2]);
$quote_3 = ($quote[3]);
$quote_4 = ($quote[4]);
$quote_5 = ($quote[5]);
$quote_6 = ($quote[6]);
$quote_7 = ($quote[7]);
$quote_8 = ($quote[8]);
echo "<div class='symbol'><div class='quote'>Company: $quote_0</div></div>";
echo "<div class='row'><div class='quote'>Last trade: $$quote_1</div>";
echo "<div class='quote'>Date: $quote_2</div>";
echo "<div class='quote'>Time: $quote_3</div>";
echo "<div class='quote'>From Previous: $$quote_4</div></div>";
echo "<div class='row'><div class='quote'>Open: $$quote_5</div>";
echo "<div class='quote'>High: $$quote_6</div>";
echo "<div class='quote'>Low: $$quote_7</div>";
echo "<div class='quote'>Volume: $quote_8</div></div>";
if (isset($_POST['get_quote']) && $_POST['get_quote'] != "") {
$ticker = $_POST['ticker'];
$get_quote = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['get_quote']);
$sqlCommand = "(SELECT id, symbol as sym FROM stockpicks WHERE symbol LIKE '%$get_quote%')";
include_once("storescripts/connect_to_mysql.php");
$query = mysql_query($sqlCommand) or die(mysql_error());
$count = mysql_num_rows($query);
if($count > 1){
$search_output .= "<hr />$count results for <strong>$get_quote/strong><hr />$sqlCommand<hr />";
while($row = mysql_fetch_array($query)){
$id = $row["id"];
$sym = $row["sym"];
$search_output .= "Item ID: $id - $sym<br />";
} // close while
} else {
$search_output = "<hr />0 results for <strong>$get_quote</strong><hr />$sqlCommand";
}
}
?>
<div class="form"> <form method="post" action="<?php echo $_SERVER['REQUEST_URI'];?>">
Get Quote: <input type="text" size="10" maxlength="10" name="ticker"/>
<input type="submit" value="Get Quote" name="get_quote" />
</form></div>
Enter any valid stock quote such as:<br>
aapl<br>
hog<br>
rimm<br>
rht<br>
<?php echo $search_output ;?>
</div>
【问题讨论】:
-
为什么你的变量中有
$$?你在用变量名吗? -
我刚刚删除了 $$...它只是一个复制和粘贴,让我的生活更轻松。我打算在最终剪辑中删除的东西。价格需要 $ 符号以及其他符号。只是忘了删除它们。我已经编辑并删除了它们。谢谢提醒。
-
所以你从雅虎获取数据好吗?到底出了什么问题?
-
我在试图弄清楚如何在用户输入之间建立联系并进行匹配以查看它是否存在于“符号”列中的表选股中时遇到了麻烦。
-
在下面查看我的答案