發生之前我已經在MySQL的表與「文」,「date_posted」和「用戶」。我目前查詢來自user = Andy的所有文本,並調用這些問題。所有來自其他用戶的其他文本字段都是最近問題的答案。引用下一個迭代在PHP
我想要的是將這些答案與最近的問題關聯起來,其循環類似於「對於每個用戶=安迪的文本,查找用戶!=安迪,直到日期>下一個用戶=安迪(問題)」
這看起來太過做作,我想知道,如果它可以大致做,因爲我已經列出,或者如果我能救自己的,我如何存儲數據或某事有些麻煩。
感謝您的任何建議。
編輯:我已經在我一直在使用插入查詢增加。
$url = "http://search.twitter.com/search.json?q=&ands=&phrase=&ors=¬s=RT%2C+%40&tag=andyasks&lang=all&from=amcafee&to=&ref=&near=&within=1000&units=mi&since=&until=&tude%5B%5D=%3F&rpp=50)";
$contents = file_get_contents($url);
$decode = json_decode($contents, true);
foreach($decode['results'] as $current) {
$query = "INSERT IGNORE INTO andyasks (questions, date, user) VALUES ('$current[text]','$current[created_at]','Andy')";
mysql_query($query);
}
$url2 = "http://search.twitter.com/search.json?q=&ands=&phrase=&ors=¬s=RT&tag=andyasks&lang=all&from=&to=amcafee&ref=&near=&within=15&units=mi&since=&until=&rpp=50";
$contents2 = file_get_contents($url2);
$decode2 = json_decode($contents2, true);
foreach($decode2['results'] as $current2) {
$query2 = "INSERT IGNORE INTO andyasks (questions, date, user) VALUES ('$current2[text]','$current2[created_at]','$current2[from_user]')";
mysql_query($query2);
}
,然後在選擇端,這就是我目前:
$results = mysql_query("SELECT * FROM andyasks");
$answers = mysql_query("SELECT * FROM andyasks WHERE 'user' != 'Andy'");
while($row = mysql_fetch_array($results))
{
if ($row['user'] == 'Andy') {
print(preg_replace($pattern, $replace, "<p>".$row["questions"]."</p>"));
}
}
while($row = mysql_fetch_array($answers))
{
print(preg_replace('/@amcafee/', '', "<p>".$row["questions"]."</p>"));
}
當我剛開始在這個項目上開始了,我可以改變任何我想要:)我已經添加了「答案」一欄。我不太熟悉SQL查詢來編寫你的建議,但在邏輯上它就像「如果用戶!= alex,插入(text,date_posted,user,answers)(文本,日期,用戶,[最最近的問題主鍵]。我是否需要通過另一個查詢將最近的問題定義爲變量?或者SQL可以取笑這個問題。謝謝! – 2009-06-12 16:24:53