im a bit stuck on this one so I thought id pass it on here.
I have a table which can be dynamicaly built with in put boxes for the y axis, x axis and for the value.
the name of the value input boxes are numbered from left to right, top to bottom.
0,1
2,3
4,5
6,7
Lets say in the input box 7 i have entered a value and i want to get the X and y axis titles.
when the form is summbited by array is built.
[heading_x] => Array
(
[0] => red
[1] => black
)
[heading_y] => Array
(
[0] => Small
[1] => Medium
[2] => Large
[3] => X-Large
)
[value] => Array
(
[1] => Array
(
[0] =>
[1] =>
)
[2] => Array
(
[0] =>
[1] =>
)
[3] => Array
(
[0] =>
[1] =>
)
[4] => Array
(
[0] =>
[1] => foo
)
The code i’ve wrote so far for finding the x and y axis out is as follows
if( preg_match( "#^([0-9]+)\-value([0-9]+)\-([0-9]?)$#is", $key, $match ) ) {
foreach( $attrDetails as $key_2 => $array ) {
if( $array['attribute_id'] == $match[1] && $val != '0' && $val != '' ) {
$options = unserialize( stripslashes( $attrDetails[$key_2]['attribute_options'] ) );
unset( $options['value'][0] );
print_r($options);
$max = count( $options['heading_x'] );
$base = $match[2] + 1;
$position_x = ( $base % $max ) + 1;
$position_y = ( ( floor( $base / $max ) - 1 ) < 0 ? 0 : floor( $base / $max ) - 1 );
if( $match[3] == '' || $base == '0' ) {
if( $pd_details->pd_activate_special_offer == '1' && $pd_details->pd_offer_price != '0.00' ) {
if( $array['attribute_type'] == '4' ) {
$cost = $val * $pd_details->pd_offer_price;
}
}else{
if( $array['attribute_type'] == '4' ) {
$cost = sprintf("%01.2f", $val * $pd_details->pd_price );
}
}
}
die($position_x . ' / ' . $position_y);
echo $options['heading_y'][$position_y-1] . ' / ' . $options['heading_x'][$position_x-1] . " amount: $val cost: $cost <br />\n";
$_SESSION['basket']['items']['top_option'][] = $options['heading_x'][$position_x-1];
$_SESSION['basket']['items']['side_option'][] = $options['heading_y'][$position_y-1];
$_SESSION['basket']['items']['amount'][] = $val;
$_SESSION['basket']['items']['price'][] = $cost;
}
}
}
the main bit being
$max = count( $options['heading_x'] );
$base = $match[2] + 1;
$position_x = ( $base % $max ) + 1;
$position_y = ( ( floor( $base / $max ) - 1 ) < 0 ? 0 : floor( $base / $max ) - 1 );
posiition y seems to be fine. My problem being lets say
floor( $base / $max ) – 1
= 3.50.
I know that 3 is the third down (or key 3 i forgot) how can i use the remainder to find the x axis?
nevermind…