Php Ari测验没有零结果

Php Ari测验没有零结果,php,mysql,database,Php,Mysql,Database,我有以下代码表: $query = sprintf('UPDATE #__ariquizstatisticsinfo SET Status = %1$s,EndDate = %2$s,MaxScore = %3$f,UserScore = %4$f,UserScorePercent = %7$f, Passed = %5$d, ElapsedTime = UNIX_TIMESTAMP(%2$s) - UNIX_TIMESTAMP(StartDate) + UsedTime WHERE Stati

我有以下代码表:

$query = sprintf('UPDATE #__ariquizstatisticsinfo SET Status = %1$s,EndDate = %2$s,MaxScore = %3$f,UserScore = %4$f,UserScorePercent = %7$f, Passed = %5$d, ElapsedTime = UNIX_TIMESTAMP(%2$s) - UNIX_TIMESTAMP(StartDate) + UsedTime WHERE StatisticsInfoId = %6$d',
            $db->Quote(ARIQUIZ_USERQUIZ_STATUS_COMPLETE),
            $db->Quote($finishedDate),
            $finishedInfo['MaxScore'],
            $finishedInfo['UserScore'],
            $finishedInfo['Passed'],
            $statisticsInfoId,
            $finishedInfo['MaxScore'] > 0 ? min(round(100 * $finishedInfo['UserScore'] / $finishedInfo['MaxScore'], 2), 100.00) : 0.00

    );
但我不需要在mysql数据库中写入0结果,因为没有正确的答案。 我改为:

    if ($finishedInfo['UserScore'] == 0.00) 
    {
    $resultes = 1.00;
    } 
    else
    {
    $resultes = $f;
    }
    $query = sprintf('UPDATE #__ariquizstatisticsinfo SET Status = %1$s,EndDate = %2$s,MaxScore = %3$f,UserScore = %4$resultes,UserScorePercent = %7$f, Passed = %5$d, ElapsedTime = UNIX_TIMESTAMP(%2$s) - UNIX_TIMESTAMP(StartDate) + UsedTime WHERE StatisticsInfoId = %6$d',
        $db->Quote(ARIQUIZ_USERQUIZ_STATUS_COMPLETE),
        $db->Quote($finishedDate),
        $finishedInfo['MaxScore'],
        $finishedInfo['UserScore'],
        $finishedInfo['Passed'],
        $statisticsInfoId,
        $finishedInfo['MaxScore'] > 0 ? min(round(100 * $finishedInfo['UserScore'] / $finishedInfo['MaxScore'], 2), 100.00) : 0.00
    );
但当我完成测试时,我犯了一个错误:

500-ariquizmodeluserquick::markquizasffinished:以下SQL 无法执行查询“更新\uuu ariquizstatisticsinfo集状态” ='Finished',EndDate='2015-04-28 07:41:06',MaxScore=2.700000,UserScore=esultes,UserScorePercent=0.000000,Passed=0,ElapsedTime=UNIX_时间戳'2015-04-28 07:41:06'- UNIX\u TIMESTAMPStartDate+UsedTime,其中StatisticsInfoId=134'。 详细信息:“字段列表”SQL=UPDATE中的未知列“esultes” joomla_ariquizstatisticsinfo集状态=‘已完成’,结束日期= “2015-04-2807:41:06”,MaxScore=2.700000,UserScore= esultes,UserScorePercent=0.000000,Passed=0,ElapsedTime= UNIX_TIMESTAMP'2015-04-28 07:41:06'-UNIX_TIMESTAMP'startdate+ 统计信息ID=134时的使用时间

提前谢谢

返回更新: 我尝试了以下代码:

   $finaluserscore = '%4$f';
   if ($finaluserscore == 0.00)
   {
   $finaluserscore = 1.00;
   } else {
   $finaluserscore = '%4$f';
   }
   $query = sprintf('UPDATE #__ariquizstatisticsinfo SET Status = %1$s,EndDate = %2$s,MaxScore = %3$f,UserScore = ' . $finaluserscore . ',UserScorePercent = %7$f, Passed = %5$d, ElapsedTime = UNIX_TIMESTAMP(%2$s) - UNIX_TIMESTAMP(StartDate) + UsedTime WHERE StatisticsInfoId = %6$d',
   $db->Quote(ARIQUIZ_USERQUIZ_STATUS_COMPLETE),
   $db->Quote($finishedDate),
   $finishedInfo['MaxScore'],
   $finishedInfo['UserScore'],
   $finishedInfo['Passed'],
   $statisticsInfoId,
   $finishedInfo['MaxScore'] > 0 ? min(round(100 * $finishedInfo['UserScore'] / $finishedInfo['MaxScore'], 2), 100.00) : 0.00
    );

但是我不明白为什么如果我得到的结果是0.00,那么我会得到1.00,如果我得到的结果超过0.00,那么我会得到1.00

我想你漏掉了一个逗号

UserScore = %4$resultes
可能是

UserScore = %4$,resultes

Thx除了我自己,一切都解决了,它现在起作用了

   $query = sprintf('UPDATE #__ariquizstatisticsinfo SET Status = %1$s,EndDate = %2$s,MaxScore = %3$f,UserScore = case when %4$f < 1.00 then 1.00 else %4$f end,UserScorePercent = %7$f, Passed = %5$d, ElapsedTime = UNIX_TIMESTAMP(%2$s) - UNIX_TIMESTAMP(StartDate) + UsedTime WHERE StatisticsInfoId = %6$d',
   $db->Quote(ARIQUIZ_USERQUIZ_STATUS_COMPLETE),
   $db->Quote($finishedDate),
   $finishedInfo['MaxScore'],
   $finishedInfo['UserScore'],
   $finishedInfo['Passed'],
   $statisticsInfoId,
   $finishedInfo['MaxScore'] > 0 ? min(round(100 * $finishedInfo['UserScore'] / $finishedInfo['MaxScore'], 2), 100.00) : 0.00
    );     
如果注释必须在sql中,而不是在php中:

UserScore=当%4$f<1.00时,则为1.00,否则%4$f结束


再次感谢大家

“字段列表”中的未知列“esults”。也许您在该字段的名称中有输入错误?也许应该是%4$r