Try with
$search = DB::table('scores')->where('score', '>', $number)->orderByRaw('RAND()')->first();
Look for numbers higher then 42, and sort it from low to high with a limit of 1.
I tried this solution, but I am getting a weird result. If ever my score is 3, the result will be 30. If the score is 2 the result will be 20 instead of 5 which is the nearest highest score.
Btw, my data is almost consist of 400 scores on my tables.
$secondsearch = DB::table('scores')->where('score', '>=', $score)->orderBy('score', 'ASC')->take(1)->first();
assuming you have the model built...
public function nextHighest($number) {
return Score::orderBy('score', 'asc')->where('score', '>', $number)->firstOrFail();
}
I didn't test that code but I think it should do what you want. Let me know, thanks.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community