我有这个代码形式Ari Quiz:
obj\Debug
但是当没有回答正确的问题时,我不需要写入mysql数据库0的结果。 我修改了:
$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
);
但是当我完成测试时我得到了一个错误:
提前谢谢!500 - AriQuizModelUserQuiz :: markQuizAsFinished():以下SQL 查询无法执行' UPDATE #__ariquizstatisticsinfo SET状态 ='已完成',EndDate =' 2015-04-28 07:41:06',MaxScore = 2.700000,UserScore = esultes,UserScorePercent = 0.000000,Passed = 0,ElapsedTime = UNIX_TIMESTAMP( ' 2015-04-28 07:41:06') - UNIX_TIMESTAMP(StartDate)+ UsedTime WHERE StatisticsInfoId = 134'。 详情:未知专栏' esultes'在'字段列表' SQL = UPDATE joomla_ariquizstatisticsinfo SET Status ='已完成',EndDate = ' 2015-04-28 07:41:06',MaxScore = 2.700000,UserScore = esultes,UserScorePercent = 0.000000,Passed = 0,ElapsedTime = UNIX_TIMESTAMP(' 2015-04-28 07:41:06') - UNIX_TIMESTAMP(StartDate)+ UsedTime WHERE StatisticsInfoId = 134
返回更新: 我试过这段代码:
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
);
但我不明白为什么如果我得到结果0.00这给我1.00如果我得到超过0.00所有相同。
答案 0 :(得分:0)
我认为你错过了一个逗号
UserScore = %4$resultes
可能是
UserScore = %4$,resultes
答案 1 :(得分:0)
感谢我所有人,但我已经解决了,现在正在努力。
$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&lt; 1.00然后1.00否则%4 $ f结束
再次向所有人致谢!