选择用户 ID 的数据库条目

问题描述

我使用的是 vBulletin 论坛软件 3.8,其中有多种方法可以提取当前用户的用户 ID:

$vbulletin->GPC['userid']
$vbulletin->userinfo['userid']
$bbuserinfo['userid']

所有这些都返回相同的值,在我的例子中 1

我创建了一个表来存储登录信息,该表存储用户 ID,如下所示:

INSERT INTO logins (userid,phpdate)
VALUES (" . $vbulletin->userinfo['userid'] . "," . TIMENOW . ")

使用 Navicat 我可以运行查询:

SELECT *
FROM logins
WHERE userid = 1
ORDER BY phpdate ASC
LIMIT 5

这给了我正确的结果,所以我然后将此查询转换为 vBulletin 格式,将 WHERE 子句更改为:

WHERE userid = $vbulletin->userinfo['userid']

这样做会引发错误:

syntax error,unexpected 'userid' (T_STRING),expecting ')'

我曾尝试将变量包装在 intval($var) IN ($var) 中,但我似乎无法使其任何变体起作用,我什至试图逃避 ' {{1 }}。

问题时间:如何在查询中选择用户 ID?

我在 $vbulletin->userinfo[\'userid\']

为了暂时克服这个问题,我在 while 循环中使用了 if 条件

PHP 7.4

尽管这不允许我限制每个用户 ID 的结果,如果我可以让 SQL 语句正常运行,我还有其他计划。

我一直在纠结这个等待一些帮助我目前的方法是:

while ($row = $result->fetch_assoc()){
    $row['phpdate'] =    vbdate( $vbulletin->options['dateformat'],$row['phpdate'],true );
    if ($vbulletin->userinfo['userid'] == $row['userid']){
        ...
    }
}

抛出无效的 SQL 错误:

$result = $db->query('
SELECT *
FROM logins
WHERE userid = ' . $vbulletin->userinfo['userid'] . '
ORDER BY phpdate ASC
LIMIT 5
');
    while ($row = $result->fetch_assoc()){
        $row['phpdate'] =   vbdate( $vbulletin->options['dateformat'],true );

     if ($vbulletin->userinfo['userid'] == $row['userid']){
      $drcpi_tbl_gutz .= '
        <li><ul class="device">
        <li class="icon">';
          $drcpi_tbl_gutz .= '<i class="fal fa-question-square fa-fw"></i>';
       $drcpi_tbl_gutz .= '</li>
        <li class="browser">' . $row['os'] . ' <small>(' . $row['browser'] . ')</small></li><li class="logindate time">' . $row['phpdate'] . '</li>
        <li class="ip-address">' . $row['ipaddress'] . ' <a class="location-lookup" title="Get approximate location of this IP address." href="https://www.iplocation.net/?query=' . $row['ipaddress'] . '"><i class="fal fa-location-arrow"></i></a></li></ul></li>
     ';
      }
    }
    $result->free();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)