开发者

how to query from more 2 tables

i tryed to do this:

    $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'
开发者_C百科 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,
    ));
}

its not work.... I need to query each user to check how many messages he wrote to various forums with each forum has a different price and then get me the price that each user has gained general

thanks again.


if i am correct you dont need that last , after $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    
));
}


If I understand you correctly, you want compulate sum for each user, try something like this: SELECT sum(phpbb_forums.price) as total_sum, ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜