2011-07-05 55 views
0

查詢我tryed做到這一點:如何從多2個表

$sql = "SELECT phpbb_users.user_id, phpbb_users.username, phpbb_users.user_colour, topic_poster, phpbb_topics.forum_id, phpbb_forums.forum_price 
FROM phpbb_topics LEFT JOIN phpbb_forums ON phpbb_topics.forum_id = phpbb_forums.forum_id 
LEFT JOIN phpbb_users ON phpbb_topics.topic_poster = phpbb_users.user_id WHERE phpbb_users.group_id = '55222' 
OR phpbb_users.group_id = '55229' 
OR phpbb_users.group_id = '55174' 
GROUP BY phpbb_users.user_id ORDER BY phpbb_forums.forum_price DESC"; 
    $result = $db->sql_query($sql); 

while ($row = $db->sql_fetchrow($result)) 
{ 

    $template->assign_block_vars('earn', array(
     'USER_ID'     => $row['user_id'], 
     'USERNAME'     => $row['username'], 
     'USER_COLOR'    => $row['user_colour'], 
     'U_USER'     => append_sid($phpbb_root_path . "memberlist." . $phpEx . "?mode=viewprofile&u=" . $row['user_id']), 
     'TOTAL_EARN'    => $price, 
     'TOTAL_UPLOADS'    => $total_price_singels+$total_price_albums, 
     'TOTAL_UPLOADS_LASTMONTH' => $total_upload_lastmonth, 
     'TOTAL_UPLOADS_MONTH'  => $total_upload_month, 
    )); 
} 

其無法正常工作.... 我需要查詢每個用戶檢查他有多少郵件寫信給各種論壇,每個論壇有不同的價格,然後得到我的價格,每個用戶已獲得通用

再次感謝。

+0

什麼是您收到的錯誤信息?它如何「不工作」? – Charx

回答

0

如果我是正確的,你不需要,去年,$total_upload_month

$sql = "SELECT phpbb_users.user_id, phpbb_users.username, phpbb_users.user_colour, topic_poster, phpbb_topics.forum_id, phpbb_forums.forum_priceFROM phpbb_topics LEFT JOIN phpbb_forums ON phpbb_topics.forum_id = phpbb_forums.forum_id LEFT JOIN phpbb_users ON phpbb_topics.topic_poster = phpbb_users.user_id WHERE phpbb_users.group_id = '55222' OR phpbb_users.group_id = '55229' OR phpbb_users.group_id = '55174' GROUP BY phpbb_users.user_id ORDER BY phpbb_forums.forum_price DESC"; 
$result = $db->sql_query($sql); 
while ($row = $db->sql_fetchrow($result)){ 
$template->assign_block_vars('earn', array(  
'USER_ID'     => $row['user_id'],   
'USERNAME'     => $row['username'],   
'USER_COLOR'    => $row['user_colour'],   
'U_USER'     => append_sid($phpbb_root_path . "memberlist." . $phpEx . "?mode=viewprofile&u=" . $row['user_id']),   
'TOTAL_EARN'    => $price,   
'TOTAL_UPLOADS'    => $total_price_singels+$total_price_albums,   
'TOTAL_UPLOADS_LASTMONTH' => $total_upload_lastmonth,   
'TOTAL_UPLOADS_MONTH'  => $total_upload_month  
)); 
} 
+0

我需要知道如何做到這一點...我告訴你我的代碼,我嘗試和它的不工作。在我的代碼中,您可以看到我的表格和我擁有的字段。我需要爲在不同論壇上發佈主題的每個用戶獲得總體價格,並且每個論壇都有不同的價格。例如:如果我在兩個論壇發帖 - forum_id1和forum_id2和forum1 = 1 $ price,forum2 = 2 $我在結果3 $中獲得....非常抱歉我的愚蠢的英語 – Ami

0

如果我理解正確的話,你要爲每個用戶compulate總和後,嘗試這樣的事情: SELECT sum(phpbb_forums.price) as total_sum, ...