0
I have the following code, where only index 0 is string:
$row[0] = $row[0];
$row[1] =(float) $row[1];
$row[2] =(float) $row[2];
$row[3] =(float) $row[3];
$row[4] =(float) $row[4];
$row[5] =(float) $row[5];
$row[6] =(float) $row[6];
I need to divide one index by the other, I’m trying like this:
$a = $row[5] / $row[6];
$row[7] =$a;
However, my table does not load.
Note: The strange thing is that if I make a sum it works.
What is going on?
Some division by zero?
– rray
@rray, yes some values are 0.
– Gabriel Tobias
Do you want to automate this with a repeat loop for example ? or just split the values you choose ? it was not very clear your goal , could give an example of values for variable
$row
to test here– Vinicius Shiguemori
Give a "print_r($Row[5] / $Row[6]);" ve if it returns an error and put it here.
– Victor Pereira
@Viniciusshiguemori, basically I need to do a percentage calculation, which would be $Row[2] + $Row[3] + $Row[5] = $total, then add $Row[2] + $Row[5] / $total.
– Gabriel Tobias
You have to create for example a
if
if the divisor$row[2] + $row[5] / $total // <- $total é o divisor;
is equal to zero skip this account, because according to the rules of mathematics it cannot be divided by 0– Vinicius Shiguemori
@Victorpereira , giving division error by 0
– Gabriel Tobias
@Viniciusshiguemori, I think that’s right, I’ll try.
– Gabriel Tobias
What is the logic of this: $Row[0] = $Row[0]; ?
– Lucas de Carvalho
@Lucascarvalho, is to assemble the lines of the Datatable. https://datatables.net/development/server-side/php_mysql
– Gabriel Tobias
@Gabrieltobias makes sense your first snippet of code? You’re assigning the array position to the same thing!
– Marconi
What do these divisions and the values themselves mean? That seems to me a XY problem
– Isac
@Isac, it’s a production performance calculation.
– Gabriel Tobias
@Viniciusshiguemori, really, the problem was the division by 0, I made the condition and it worked. Thank you all for the answers!
– Gabriel Tobias