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

matilarab's avatar

Math operations on query

Hey guys I have a table with two columns that have to be divided (A/B) and new calculated every time i reload my web page.

I tried placing this query on my controller and als php on my view, but i cannot manage

    for ($i=0; $i < 0; $i++) {
      Product::update('Runs' => $products[$i]['Amount']/$products[$i]['Amount_Run']);
    }

anybody has an Idea?

0 likes
2 replies
Tray2's avatar

Read this one out loud

for ($i=0; $i < 0; $i++)

For $i is equal to zero and while $i is less then zero then inrement $i by one.

If it even runs it does it one time and one time only.

Not knowing where you more about your code, I would suggest you create an API controller to handle this and use ajax to hit the endpoint to change this number,

Also I small reminder never update anything in the database with a GETrequest.

2 likes
matilarab's avatar

@TRAY2 - ohh, thanks for pointing that out! and also thank you for your suggestion!

Please or to participate in this conversation.