Forum Moderators: coopster

Message Too Old, No Replies

Checkbox and Array Issues

         

briesm

6:49 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



So I have an array that holds information, I am unsetting it and unshifting in the case that a checkbox is selected and a remove items submit form is clicked.
I am assuming that these unsets with the shift will effectively remove the 6 items from the array (each order has six components), and shift the next order down to where this one was? So when I get to continue I have to subtract 6 from $itr because it would add 6 as my for loop suggests? I omitted some stuff in the for loop..

if($_POST["item$i"]== "checked"){

$_SESSION['total'] = $total-$ordersArray[$itr+4];

unset ($ordersArray[$itr]);
unset ($ordersArray[$itr+1]);
unset ($ordersArray[$itr+2]);
unset ($ordersArray[$itr+3]);
unset ($ordersArray[$itr+4]);
unset ($ordersArray[$itr+5]);
array_unshift ($ordersArray, array_shift ($ordersArray));

$itr-6;
$i++;
continue;
}

Checkbox code down here:

echo '<input type="checkbox" name="item';
echo $i;
echo '" value="checked">';

mcibor

8:34 pm on Jun 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This code:

$itr + 6; //doesn't change the $itr - it returns just a number

But so the $itr isn't changed nor by unset ($ordersArray[$itr+3]);

eg:
$itr = 2;
unset ($ordersArray[$itr+3]); //ordersArray[5], itr = 2
$itr - 6;// = -4, itr = 2
$itr++;// itr = 3
$itr += 6; //itr = 9

So you see. You don't have to do itr-6, as it's not working as such.
BTW there's no for loop in your example. And what's $i? And what's $itr?

Hope this shows you some direction
Best regards
Michal Cibor

PS. Moreover if you write your checkbox name as
<input type="checkbox" name="item[]"> etc.. you will find that all checkbox turned into an array containing true and false (depends on the check). It may be easier to operate on array that on item$i

briesm

9:06 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



I omitted a bunch but that $itr - 6 statement was the problem lol. And here I was looking in all the wrong places. Thanks a bunch for the help :>)