我的字典數據庫與4桌設計成類似MySQL的左連接重複行
words
wordid | lemma
senses
wordid | synsetid
synsets
synsetid | definition
samples
synsetid | sample
所以我使用查詢下面讓所有感覺的定義在工作和樣品
if(isset($searchterm)){
echo "<b>".$searchterm."</b><hr>";
// QUERY TO FIND SENSES
$senses_query="SELECT
words.lemma,words.wordid,
senses.wordid,senses.synsetid,
synsets.synsetid, synsets.definition,
samples.synsetid, samples.sample
FROM
words
LEFT JOIN
senses ON words.wordid=senses.wordid
LEFT JOIN
synsets ON senses.synsetid=synsets.synsetid
LEFT JOIN
samples ON senses.synsetid=samples.synsetid
WHERE
words.lemma REGEXP '^$searchterm$'";
$senses_query_result = mysql_query($senses_query) OR die("sense alamadım.<br>".mysql_error());
$num=mysql_num_rows($senses_query_result);
while($sensesFound = mysql_fetch_array($senses_query_result)){
echo " " . $sensesFound['lemma'] . "";
echo " " . $sensesFound['definition'] . "";
echo " " . $sensesFound['sample'] . "";
echo "<br>";
}
}
的問題是:如果有一個以上的定義樣本,它會像這樣重複。
definition 1 sample 1
definition 1 sample 2
definition 2 sample 1
definition 2 sample 2
definition 2 sample 3
e.t.c
我喜歡像
definition 1 sample 1 sample 2
definition 2 sample 1 sample 2 sample 2
我試着選擇GROUP_CONCAT行,但它concats所有定義的所有樣品爲單一。
是否有可能與MySQL查詢或我應該使用PHP來處理這種工作。
在此先感謝
爲什麼要使用正則表達式,而不是'LIKE'? –