EchoFool Posted February 26, 2008 Share Posted February 26, 2008 I am having difficulty understanding arrays. I read through page about them but didn't explain how to get it working via a form with checkboxes and inputboxes to set the array... <input type="text" size="16" name="Quantity[<?=$Array?>]" value=""> <input type="checkbox" name="Checkbox[<?=$Array?>]" value="<?=$ItemID?> I have this in a while loop that loads a list of items, and what it does is, it puts the itemID in the checkbox...so the selected checkboxes will have a list of ItemID's. Then with that it is meant to grab the quantity from the Quantity input box adjacent to it.. so the array would end up forming like this: Id | Quantity 2 | 34 5 | 2 6 | 23 I think i got it right with the above two lines but I don't know how to call it up on a processing page to use the data from the array Link to comment https://forums.phpfreaks.com/topic/93225-array-help/ Share on other sites More sharing options...
Barand Posted February 27, 2008 Share Posted February 27, 2008 Only checked checkbox values are posted, so <?php foreach ($_POST['Checkbox'] as $k = $id) { $qty = $_POST['Quantity'][$k]; // get corresponding qty // process $id and $qty } Link to comment https://forums.phpfreaks.com/topic/93225-array-help/#findComment-477580 Share on other sites More sharing options...
EchoFool Posted February 28, 2008 Author Share Posted February 28, 2008 So do i even need to have the names : Checkbox[<?=$Array?>] Quantity[<?=$Array?>] For the 2 input boxes still then ? Link to comment https://forums.phpfreaks.com/topic/93225-array-help/#findComment-479486 Share on other sites More sharing options...
Barand Posted February 28, 2008 Share Posted February 28, 2008 Only checked c/boxes are posted but you need to make sure that textbox[N] belongs with checkbox[N] so <?php $count=0; while (.....) { <input type="text" size="16" name="Quantity[<?=$count?>]" value=""> <input type="checkbox" name="Checkbox[<?=$count?>]" value="<?=$ItemID?> $count++; } Link to comment https://forums.phpfreaks.com/topic/93225-array-help/#findComment-479492 Share on other sites More sharing options...
EchoFool Posted February 28, 2008 Author Share Posted February 28, 2008 Oh i see so the $Count for both of them would then equal the same value which is how they are linked? I think i understand now Thanks Barand. SOLVED Link to comment https://forums.phpfreaks.com/topic/93225-array-help/#findComment-479519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.