【发布时间】:2021-11-17 20:50:45
【问题描述】:
在这个foreach中,我使用一个函数来拉取分数,我将从foreach得到的值写入到函数中。
foreach($surveys AS $s) {
$surList[$s->cat][] = ["id" => $s->id, "title" => $s->title, "score" => SurveyController::getScore($s->id),"subtitle" => SurveyController::getSubtitle($s->id,SurveyController::getScore($s->id)) ];
}
并且在这个函数中返回与我们在数据库中使用 case-when 得到的分数相对应的消息
function getSubtitle($id,$score){
$surveys=DB::table("methodolgy")->where("main_survey",$id)->selectRaw("*, (CASE WHEN ".$score." BETWEEN start AND end THEN message ELSE 'bos' END) AS sonuc")->having("sonuc","!=","'bos'")->orderBy("id","ASC")->first();
return isset($surveys->message) ? $surveys->message : "Activity Not Found";
}
问题是,当我在 SQL 中尝试我的query 时,结果是correct,但是当我在我的网站上尝试它时,它总是返回我的方法表中的第一条记录。 我找不到它为什么会这样。
感谢您的帮助。
【问题讨论】: