0
Next, I have a table with several values and I need to compare the values of several columns, I did this with PHP and managed to separate the highest value, follows the code:
while($aux = mysqli_fetch_array($query))
{
$cb = $aux['cb'];
$rb = $aux['rb'];
$lb = $aux['lb'];
$rwb = $aux['rwb'];
$lwb = $aux['lwb'];
$cdm = $aux['cdm'];
$cm = $aux['cm'];
$rm = $aux['rm'];
$lm = $aux['lm'];
$cam = $aux['cam'];
$cf = $aux['cf'];
$rf = $aux['rf'];
$lf = $aux['lf'];
$rw = $aux['rw'];
$lw = $aux['lw'];
$st = $aux['st'];
$Maior = 0;
$arr = array($cb,$rb,$lb,$rwb,$lwb,$cdm,$cm,$rm,$lm,$cam,$cf,$rf,$lf,$rw,$lw,$st);
foreach ($arr as &$value) {
if($value > $Maior) {
$total = $value;
}
$Maior = $value;
}
unset($value);
}
echo $total;
What I’m not able to think logically is how to do for example, if cf is the highest, how to assign a variable the text 'cf' and with that I would make an Insert in a table, in that filter I know that cf is the highest.
Honestly, your code is a bit messy, there is something there that doesn’t even need, ta missing a lot of information: What are these variables
$cb
,$rb
, ...? What is the$total
and$maior
? Whyunset($value);
? What is the purpose of the code? Maybe what you want can be done directly in SQL– Costamilam
are the values sought by the select that is above the while, the goal is to take the higher value, when found instead of saving the value I want to save the column name, for example "CF"
– Ricardo