0
即時通訊有點卡在這一個,所以我想編號傳遞在這裏。使用餘數來選擇輸入
我有一個表,它可以動態地在y軸,x軸和數值框中放入。
值輸入框的名稱從左到右,從上到下進行編號。
0,1
2,3
4,5
6,7
讓我們說在輸入框中7我輸入了一個值,我想要得到X和Y軸標題。
當窗體被數組summbited時被構建。
[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
)
到目前爲止,我已經寫了尋找X和Y軸出來的代碼如下
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;
}
}
}
是
$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中的主比特似乎要被罰款。我的問題的存在可以說
地板($基地/ $最大值) - 1
= 3.50。
我知道3是第三下(或關鍵3我忘了)我怎樣才能使用其餘的找到X軸?
因爲你已經回答了你自己的問題,請標記爲「接受」,因此它不會在unanaswered問題列表中顯示的答案。謝謝。這也有助於任何發現此頁面的人在未來尋找同一問題的答案。 – Spudley 2011-01-21 09:01:05