-1
---- HTML Form ----

<?php
$query = mysql_query("SELECT * FROM package WHERE status = 0");
while($row = mysql_fetch_array($query)){
$package_id = $row['id'];   
$package_name = $row['name'];   
?>
<tr>
<td><?php echo $package_name; ?></td>
<td><input type="text" name="txt[]" id="quantity" placeholder="0">
 --------- Aboue input is for quantity of those products----------
</td>
</tr>                                                       
<?php 
}
?>

Here is the code for process.php for this form POST method
//
<?php
if(isset($_POST['submit'])){
$alTxt= $_POST['txt'];
$N = count($alTxt); 
for($i=0; $i < $N; $i++){
  echo($alTxt[$i]);
}
}
?>

Now the output of process.php is 125 (If i put the input in 3 textbox like 1,2,3) Now the problem i got the quantity of the product , but how can i get the each product id or product name along with the quantity ? So i can get the calculation in process.php ? Can anyone help me with the codes ??

Lorry.B
  • 45
  • 1
  • 5

1 Answers1

0

HTML:

<input type="text" name="txt[<?= $product["id"] ?>]" id="quantity" placeholder="0">

Please note you can also use nested attributes in HTML:

<input type="text" name="txt[<?= $product["id"] ?>][quantity]" value = "22">
<input type="text" name="txt[<?= $product["id"] ?>][name]" value = "product name">

PHP:

foreach($_POST['txt'] as $productId => $quantity) {
   echo $productId . " " .$quantity;
}
knagode
  • 5,816
  • 5
  • 49
  • 65