Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Maximus1's avatar

Query with a where clause and a fraction

I have this query in my controller but it does not return anything

 $global_size = Boutique::select('price')->where('size', 7/8)->first();

if I replace the size with an integer like so below, it works

$global_size = Boutique::select('price')->where('size', 7)->first();

How can i make this query work with the size in fraction? The sizes for the boutique clothes are all in fractions like 7/8, 8/9, 10/11......... How to make this work ?

$global_size = Boutique::select('price')->where('size', 7/8)->first();
0 likes
5 replies
kevinbui's avatar

7/8 is like 0.875. Your size column value got to be exactly that value to match.

I reckon you might want to use the ROUND method in mysql OR the round method in php for those conditions to work.

jlrdw's avatar

Are you sure that is supposed to be a fraction and not a range.

Maximus1's avatar

I switched code by changing 7/8 to 7-8 and it worked.

$global_size = Boutique::select('price')->where('size', 7-8)->first();

I still wonder if there is a way to do it in fraction like 7/8.

Snapey's avatar
Snapey
Best Answer
Level 122

your code now says where size = -1 since 7 minus 8 is -1

if your product is stored with a size stated as 7/8 then this is a STRING and you should query ->where('size', '7/8')

Please or to participate in this conversation.