I'm trying to create an inventory tracker. My problem is that the inventory can be anywhere from 1 item to 1 metric buttload (give or take) of items. The basic form is this:
eq.issue.php
<form name="form" method="post" action ="issue.e.php">
<?
$kit_query = mysql_query("SELECT * FROM eq_kit");
while($fetch_kits = mysql_fetch_array($kit_query){
$kitId = $fetch_kits['kit_id'];
$kitSn = $fetch_kits['kit_sn'];
$kitQty = $fetch_kits['kit_qty'];
?>
<tr>
<td>
<input type="checkbox" name="kit_row[]" value="<?=$kitId?>" id="<?=$kitId?>">
</td>
<td>
<input name="qty[]" type="text" id="<?=$kitQty?>" value="<?=$kitQty?>">
</td>
<td>
<input name="sn[]" type="hidden" id="<?=$kitSn?>" value="<?=$kitSn?>"
</td>
</tr>
<? } ?>
<input type="submit" name="Submit" id="Submit" value="Submit">
</form>
on the receiving side:
issue.e.php
<? // all the database crap
if(is_array($kit_row)){
foreach($_POST['kitrow'] as $key=>$val){
$sn=$_POST['sn'];
$serial = $sn[$val];
$qty = $_POST['qty'];
$quant = $qty[$val];
mysql_query("INSERT INTO eq_issue SET issue_sn = '$serial', issue_qty = '$quant'")or die(mysql_error());
This works well for an individual item as well as consecutive items.
With an example of this as my eq.issue.php form:
|Check | Qty | SN |
====================
| X | 100 |12345|
| | 1 |23456|
| | 1 |98765|
| X | 999 |19283|
====================
|Submit|
My problem is that if I choose the 1st and 4th option for example, the arrays now appear like this:
kit_row => Array
0 => 4
1 => 3
qty => Array
0 => 100
1 => 1
2 => 1
3 => 999
sn => Array
0 => 12345
1 => 23456
2 => 98765
3 => 19283
Thus, as my script plays out, I get values for the 4th option as kit_row => 3 qty => 1 sn=> 23456, where I want it to display kit_row=> 3 qty => 999 sn => 19283.
Any suggestions on how I can make this work? For a better visual reference, I am trying to acheive the same concept as PHPMyAdmin's multi-value insert page using checkboxes to say which group (or rows) of records I want to insert.