Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Dbal和PhPBB函数的PhP SQL查询_Php_Sql_Phpbb_Dbal - Fatal编程技术网

使用Dbal和PhPBB函数的PhP SQL查询

使用Dbal和PhPBB函数的PhP SQL查询,php,sql,phpbb,dbal,Php,Sql,Phpbb,Dbal,好的,在这里,我再次尝试从头开始编写代码,但我不能完全正确。。。我只想检索用户所在的组id(不包括注册用户),然后在以下语句中使用该id:如果检索到的组id为10,则返回指定的消息,否则从检索到的组id中删除该用户并将其放入组id 10中。这就是我到目前为止所做的,但我认为我在dbal中的某个地方犯了一个错误。。。至于用户组add/del函数,我不确定我是否正确使用了它们。。。此外,我还包括了函数_user.php,但不确定我是否真的需要,也不确定我是否正确放置了它。这是我得到的,有什么帮助吗

好的,在这里,我再次尝试从头开始编写代码,但我不能完全正确。。。我只想检索用户所在的组id(不包括注册用户),然后在以下语句中使用该id:如果检索到的组id为10,则返回指定的消息,否则从检索到的组id中删除该用户并将其放入组id 10中。这就是我到目前为止所做的,但我认为我在dbal中的某个地方犯了一个错误。。。至于用户组add/del函数,我不确定我是否正确使用了它们。。。此外,我还包括了函数_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']);
    }

好吧,我让它工作了。。。这是代码。使用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;

好吧,我让它工作了。。。这是代码。使用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;