Forums / General Questions / Get max value from attributes values

Get max value from attributes values

Results 1 to 7 of 7
14 Oct 2012, 10:52
#1
tips007 avatar

tips007

New Zenner

Join Date:
Oct 2012
Posts:
52
Plugin Contributions:
0

Get max value from attributes values

hello
in checkout_confirmation file, i find the code nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']))
i want to use max() for my attributes values (all my attributes avlues are numbers)
i tried echo max(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']))
and echo max(array(zen_output_string_protected($order->products[$i]['attributes'][$j]['value'])))
they don't work
any ideas?
15 Oct 2012, 05:22
#2
tips007 avatar

tips007

New Zenner

Join Date:
Oct 2012
Posts:
52
Plugin Contributions:
0

Re: Get max value from attributes values

each product has only one attribute, all the attribute values are numbers

ex.
product A with attribute value 6
product B with attribute value 3
product C with attribute value 8

if i add <? php echo zen_output_string_protected($order->products[$i]['attributes'][$j]['value']); ?> to tpl_checkout_confirmation_default
it displays
638

if i add <? php echo zen_output_string_protected($order->products[$i]['attributes'][$j]['value']) . '<p>'; ?>
it displays
6
3
8

now i want to get the max number from 6, 3, 8

the code below doesn't work
max(array(zen_output_string_protected($order->products[$i]['attributes'][$j]['value'])))
max(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']))

is there anyone could help? thanks
16 Oct 2012, 15:34
#3
tips007 avatar

tips007

New Zenner

Join Date:
Oct 2012
Posts:
52
Plugin Contributions:
0

Re: Get max value from attributes values

use the code below
[PHP]
<? php
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
echo zen_output_string_protected($order->products[$i]['attributes'][$j]['value']);
}
}
?>
[/PHP]

you'll get the result
638

if you add the <p> to it, such as echo zen_output_string_protected($order->products[$i]['attributes'][$j]['value']) . '<p>';
you'll get
6
3
8

now i want to get the max number from 6, 3, 8
any one could help?
17 Oct 2012, 05:47
#4
tips007 avatar

tips007

New Zenner

Join Date:
Oct 2012
Posts:
52
Plugin Contributions:
0

Re: Get max value from attributes values

anyone?
17 Oct 2012, 06:22
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Posts:
21,876
Plugin Contributions:
6

Re: Get max value from attributes values

[PHP]$attrib_max = 0;
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
$attrib_max = ($attrib_max > $order->products[$i]['attributes'][$j]['value'])? $attrib_max: $order->products[$i]['attributes'][$j]['value'];
}
}[/PHP] $attrib_max will end up as the max of the attribute values.
17 Oct 2012, 08:09
#6
tips007 avatar

tips007

New Zenner

Join Date:
Oct 2012
Posts:
52
Plugin Contributions:
0

Re: Get max value from attributes values

you are a genius!
thank you
17 Oct 2012, 15:01
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Posts:
21,876
Plugin Contributions:
6

Re: Get max value from attributes values

A simpler version of the comparison uses the PHP max() function:[PHP]
$attrib_max = max($attrib_max, $order->products[$i]['attributes'][$j]['value']); [/PHP]