如果你想獲得的所有的話,那麼你的加盟條件不允許你這樣做
w.word_word = \"$keyword\"
您的查詢可以寫成如下
$sql = "SELECT p.page_url as url, COUNT(*) as occurences "
. "FROM page p "
. "INNER JOIN occurence o ON p.page_id = o.page_id "
. "INNER JOIN word w ON w.word_id = o.word_id "
. "GROUP BY p.page_id "
. "ORDER BY occurences DESC "
. "LIMIT {$results}";
$result = mysql_query($sql);
這將抓住word
表中的所有單詞,從而爲您提供(據我所知)需要的結果。
如果你有興趣的幾句話,然後就可以使用IN
陳述(由開發中的意見建議)和您的查詢就會變成:
$my_keywords = array('apple', 'banana');
// This produces: "apple", "banana" and assumes that all of your
// keywords are in lower case. If not, you can transform them to lower
// case or if you don't want that, remove the LOWER() function below
// from the WHERE
$keywords = '"' . implode('","', $my_keywords) . '"';
$sql = "SELECT p.page_url as url, COUNT(*) as occurences "
. "FROM page p "
. "INNER JOIN occurence o ON p.page_id = o.page_id "
. "INNER JOIN word w ON w.word_id = o.word_id "
. "WHERE LOWER(w.word_word) IN ({$keywords}) "
. "GROUP BY p.page_id "
. "ORDER BY occurences DESC "
. "LIMIT {$results}";
$result = mysql_query($sql);
最後,請嘗試使用mysqli
代替mysql
,或PDO。
HTH
使用在MySQL ... – Dev
確保你逃脫輸入也或使用PDO或類似的更安全的技術。一個searchphrase應該放在引號'\「$ keyword \」'中。 – jtheman
是的,您可以在('word1','word2',...)中使用w.word_word。只是匹配wordcount並不是很精確,但如果你想保持簡單... –