【问题标题】:PhP SQL Query Using Dbal and PhPBB Functions使用 Dbal 和 PhPBB 函数的 PhP SQL 查询
【发布时间】:2012-06-17 14:08:07
【问题描述】:

好的,在这里我再次尝试从头开始编写代码,但我无法完全正确...我要做的就是检索用户所在的组 id(不包括注册用户),然后使用在以下语句中:如果检索到的 group_id 是 10,则返回指定的消息,否则从检索到的 group_id 中删除用户并将它们放入 group_id 10。这是我到目前为止所拥有的,但我认为我在某处犯了错误dbal ...至于用户组添加/删除功能,我不确定我是否正确使用它们...我还包括了functions_user.php,但不确定我是否真的需要或是否放置它正确。好吧,这就是我所拥有的,有什么帮助吗?

    $integer = 2;

    $sql = 'SELECT group_id FROM ' . USER_GROUP_TABLE . '
            WHERE user_id = ' . (int) $user->data['user_id'] . "
            AND group_id != '" . (int) $integer . "'";
    $result = $db->sql_query($sql);

    if ($result == 10)
    {
       $message = sprintf($user->lang['CANNOT_USE_TRAVEL_ITEM'], $this->data['name']);
    }
    else
    {
       include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

       $userid = $user->data['user_id'];

       group_user_add((10), array($user_id));
       group_user_del(($result), array($user_id));

       $message = sprintf($user->lang['TRAVEL_ITEM_NOW_USE'], $this->data['name']);
    }

【问题讨论】:

    标签: php sql phpbb dbal


    【解决方案1】:

    好的,我得到了它的工作......这是代码。使用 group_memberships 函数来消除 SQL 查询以及为 group_user_add 和 group_user_del 函数提供正确的布尔结果。

        global $user, $shop, $db, $phpEx, $phpbb_root_path;
    
        $this->remove_item();
    
        include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
    
        if (group_memberships(10,$user->data['user_id'],true))
        {
           $message = sprintf($user->lang['CANNOT_USE_TRAVEL_ITEM'], $this->data['name']);
        }
        else
        {
           $groups = group_memberships(false,$user->data['user_id']);
           foreach ($groups as $grouprec)
           {
                   $groupid = $grouprec['group_id'];
           }
    
           group_user_add((10), array($user->data['user_id']));
           group_user_del(($groupid), array($user->data['user_id']));
    
           $message = sprintf($user->lang['TRAVEL_ITEM_NOW_USE'], $this->data['name']);
        }
    
        return $message;
    

    【讨论】:

      猜你喜欢
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-21
      • 2021-04-13
      • 2015-02-24
      • 1970-01-01
      相关资源
      最近更新 更多