【问题标题】:Using SQL Query to Define min/max for Random_int使用 SQL 查询定义 Random_int 的最小值/最大值
【发布时间】:2020-06-29 16:12:10
【问题描述】:

我正在尝试使用 SQL 查询来定义 radnom_int 函数的最小值/最大值。

private function doPreEventStart($user) {
    $MaxResult = db_fetch_item("SELECT max(resultid) FROM ResultPackage
      where ResultPackage.slotid like ‘%{$slot_id}'
      and ResultPackage.PackageID like '%{$user->packageid}%'
      ORDER BY resultid asc LIMIT 1")
    $MinResult = db_fetch_item("SELECT min(resultid) FROM ResultPackage
        where ResultPackage.slotid like ‘%{$slot_id}'
        and ResultPackage.PackageID like '%{$user->packageid}%'
        ORDER BY resultid asc LIMIT 1")
     $this->curResultId =  var_dump(random_int($MinResult,$MaxResult)
    }

到目前为止,这还没有奏效,当我尝试运行文件时出现以下错误。

PHP Parse error:  syntax error, unexpected ';' in /var/www/html/VC/server-vc-RNG.php on line 761
PHP Parse error:  syntax error, unexpected '}' in /var/www/html/VC/server-vc-RNG.php on line 762
PHP Parse error:  syntax error, unexpected '}' in /var/www/html/VC/server-vc-RNG.php on line 762
PHP Parse error:  syntax error, unexpected '$MinResult' (T_VARIABLE) in /var/www/html/VC/server-vc-RNG.php on line 757

请帮我看看错误。

【问题讨论】:

  • 您在每个 PHP 语句的末尾缺少;
  • 不需要使用两个查询。 SELECT MIN(resultid) AS minresult, MAX(resultid) AS maxresult FROM ...
  • 不要在查询中使用大引号。编辑代码时关闭“智能引号”。
  • 你在哪里设置变量$slot_id。不是函数参数,也没有声明global $slot_id;
  • 哪一行是761?该错误表明存在意外的;,但该字符并未出现在您发布的代码中的任何位置。

标签: php mysql random


【解决方案1】:

清理了括号和不正确的引号:

private function doPreEventStart($user) {
    $MaxResult = db_fetch_item("SELECT max(resultid) FROM ResultPackage
      where ResultPackage.slotid like '{$this->curSlotId}'
      and ResultPackage.PackageID like '%{$user->packageid}%'
      LIMIT 1");
    $MinResult = db_fetch_item("SELECT min(resultid) FROM ResultPackage
        where ResultPackage.slotid like '{$this->curSlotId}'
        and ResultPackage.PackageID like '%{$user->packageid}%'
        LIMIT 1");
    $this->curResultId =  var_dump(random_int($MinResult,$MaxResult));
   }

创建一个新错误:

Call to undefined function random_int()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    • 2019-03-13
    • 1970-01-01
    相关资源
    最近更新 更多