我有一個ajax搜索引擎。如果沒有過濾器打開,我想查詢每個表格的標題。在這個例子中,只有兩個表。 music_page和restaurant_page。查詢多個表格輸出重複結果
public function Any_Category_Name($search_title) {
$query = mysql_query("SELECT music_page.title AS music_title,
restaurant_page.title AS restaurant_title
FROM music_page,
restaurant_page
WHERE music_page.title
LIKE '%$search_title%' OR
restaurant_page.title
LIKE '%$search_title%'");
while($fetch = mysql_fetch_assoc($query)) {
$music_title = $fetch['music_title'];
$restaurant_title = $fetch['restaurant_title'];
echo '<b>Restaurant:</b> '.$restaurant_title.'<br />';
echo '<b>Music Spot:</b> '.$music_title.'<br />';
}
}
這是輸出,當你輸入一個字母/搜索:
Restaurant: Giordanoes
Music Spot: jazz showcase
Restaurant: Giordanoes
Music Spot: The Green Mill
Restaurant: Giordanoes
Music Spot: ayooooo
Restaurant: Giordanoes
Music Spot: ayoooooooo
Restaurant: Giordanoes
Music Spot: new one
Giordanoes是restaurant_page表中唯一的一行。它會輸出到music_page中的每一行。我該如何補救?
要加入兩個表(music_page和restaurant_page)一起表music_page有多對一的關係表restaurant_page –