2012-04-20 116 views
1

我有5個表,我希望從所有鏈接到一個名爲pubs表的數據。mySQL沒有得到所有記錄

special_offers有3條涉及到酒館 事件有4條涉及到酒館

但是我只取回第一個事件和special_offers。它似乎沒有構成一個多層次的數組。我已經嘗試過加入和內心的聯繫,我不知道可能會出現什麼問題。

SELECT pubs.*, special_offers.*, `events`.*, vote.* 
    FROM pubs 
    Inner Join `events` 
     ON pubs.id = `events`.pubID 
    Inner Join special_offers 
     ON pubs.id = special_offers.pubID 
    Inner Join vote 
     ON pubs.id = vote.pubID 
    WHERE pubs.id = 48 

下面是print_r的輸出

Array (
[0] => 48 
[id] => 1 Harveys 
[name] => Harveys 
[sun] => 10am-2.30am 
[31] => 1 
[32] => 4 
[special_dayID] => 4 
[33] => 48 
[pubID] => 48 
[34] => 2.50 Drinks 
[title] => Kodakid 
[35] => All drink 2.50 get them while there hot! or cold! 
[desc] => Kodakid are playing! 
[36] => 1 
[37] => 48 
[38] => 2012-04-30 
[date] => 2012-04-30 
[39] => Kodakid 
[40] => & others 
[subtitle] => & others 
[41] => Kodakid are playing! 
[42] => kodakid.jpg 
[img] => kodakid.jpg 
[43] => 1 
[44] => 48 
[45] => 3 
[price_range] => 3 
[46] => 5 
[atmosphere] => 5 
[47] => 2 
[food] => 2 
[48] => 4 
[service] => 4 
[49] => 3 
[value] => 3 
[50] => Waterford City 
[county] => Waterford City) 

感謝

+1

可不可以打印print_r輸出? – worenga 2012-04-20 16:04:16

+0

您可以使用blockquote標籤重新格式化輸出嗎?閱讀很痛苦。 – 2012-04-20 16:04:25

+0

謝謝,未來會確認 – 2012-04-20 16:20:39

回答

1

你是如何做的實際查詢? MySQL不支持嵌套數組或行。結果集由零個或多個行組成,每行都是一個或多個數字,字符串,日期等。

你在做什麼就是要求一個包含所有四個表中所有列的結果集。因爲你使用INNER連接,所以你要求MySQL只返回所有四個表中存在的行。因此,在events中沒有關聯行的pubs中的ID將不會包含在結果集中,即使它在另外兩個中包含行也是如此。

要做你在問什麼,你可以使用單獨的查詢(一個用於事件,一個用於投票等)。您還可以嘗試使用LEFT JOIN而不是INNER JOIN或子查詢和聚合器(如GROUP_CONCAT),但這取決於您計劃如何處理這些信息。

+0

感謝您的回覆。我之前使用過cakephp,我習慣於多級數組。認爲它會與簡單的查詢類似。不確定。我將使用單獨的查詢。 – 2012-04-20 16:20:12