2014-02-26 47 views
0

數據你好,我有這個疑問:Opencart的retriving從3個表

$sql = "SELECT email_id as name,competition_rate as rate, competition.competition_id, competition.end_date 
FROM " . DB_PREFIX . "competition_winners as competition_winners, 
    ". DB_PREFIX . "competition as competition, 
    ". DB_PREFIX . "customer as customer 

WHERE competition.competition_id = competition_winners.competition_id and customer.email=competition_winners.email_id"; 

我需要的是以檢索另一行稱爲從表負荷消費comptition_rate。我正在使用opencart,並且將它顯示在與作爲名稱顯示的客戶電子郵件相同的行中顯示。它是否可能以及它可能是圓頂?

P.s.稍微更改了一些代碼,但無法顯示所有結果,只顯示competition_rate或電子郵件。

+0

我有2個表A和B.我需要從表C中獲取名稱字段。我正在使用opencart。請幫幫我。 ---你的問題是這樣的。我們需要關於所有 表的詳細信息。 –

+0

對不起,如果我sc起你和其他人。通常我有3張桌子,我只需根據表格參數電子郵件從表格c或客戶字段中選擇數據competition_winners – user3343374

+0

您有沒有聽說過「JOIN」?您的查詢和數據庫結構不正確。您應該使用'JOIN's,而不是使用'email = email_id'作爲比較的唯一鍵您應該使用主鍵。 – shadyyx

回答

0
$sql = "SELECT email_id as name,customer.comptition_rate as newcomrate,competition_rate as rate, competition.competition_id, competition.end_date 
FROM " . DB_PREFIX . "competition_winners as competition_winners, 
    ". DB_PREFIX . "competition as competition, 
    ". DB_PREFIX . "customer as customer WHERE competition.competition_id = competition_winners.competition_id and customer.email=competition_winners.email_id"; 

嘗試此查詢,你會得到這個newcomrate領域

0

數據試試這個:

$sql = "SELECT email_id as name,customer.comptition_rate as rate, competition.competition_id, competition.end_date FROM " . DB_PREFIX . "competition_winners as competition_winners, ". DB_PREFIX . "competition as competition, ". DB_PREFIX . "customer as customer WHERE competition.competition_id = competition_winners.competition_id and customer.email=competition_winners.email_id"; 

有一個愉快的一天!

+0

非常感謝你們!有用。我只做了精簡,我添加了查看和控制器文件的費率指數。 – user3343374