Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

php - How to check whether a number lies between 2 values using Laravel query

I have to trigger a mail when student crosses several stages . I have two tables

  1. studentreward_point_categories and
  2. student_reward_points.

If any student reaches a stage then need to send a mail. How to get category from db .

Reward point Category table.

enter image description here

  1. Student reward point table.

enter image description here

If for student_id = 19 have 345 points How to get his reward category. i have tried below code.

$total_point = StudentRewardPoint::where('student_id', $request->student_id)
    ->sum('points');
if(!empty($total_point)){
    return $pointCategory = RewardPointCategory::where('from_value','>=', $total_point)
        ->where('to_value','<=',$total_point)
        ->where('status',1)
        ->first();
}

Using this query I'm not able to get user reward point category.

question from:https://stackoverflow.com/questions/66064884/how-to-check-whether-a-number-lies-between-2-values-using-laravel-query

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are quering it totally wrong!! From my point of view swap your '<=' and '>='

return $pointCategory = RewardPointCategory::where('from_value','<=',$total_point)- 
    >where('to_value','>=',$total_point)->where('status',1)->first();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...