1

I have a page that lists all the products bought in a particular consingment. The user can then choose which products to re-order (by clicking on a checkbox) and input a quantity (text input). These are then passed onto another page (listbyconsg.php) that will add the details into a new table, but I can't seem to get this working and would appreciate direction or help. Can anyone help? Thanks.

$con=$_REQUEST['consignment'];

$sql = "SELECT * FROM products,supplier
WHERE  products.consignment= $con  
AND products.supplier = supplier.supplierID
ORDER BY products.supplier";


$result = mysql_query($sql, $link);
?>
<form action='listbyconsg.php' method='post'>
<?
echo "<table  cellpadding='0' cellspacing='0' border='1'>";
echo "<tr> <th>Description</th> <th>Product Size</th> <th>Barcode</th> <th>Product Code</th> 
    <th>Image</th> <th> # </th> <th> Quantity </th></tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>"; 
echo $row['description'];   
echo "</td><td>"; 

echo $row['productSize'];
echo "</td><td>"; 

echo $row['barcode'];
echo "</td><td>"; 

echo $row['productCode'];
echo "</td><td align='center'>"; 

echo '<img src="http://bargainsupplies4u.co.uk/productpics/' . $row['barcode'] . '.jpeg">';
echo "</td>";  ?>

<td><input name="checkbox[]" type="checkbox" id="checkbox[]"  value="<?= $row['id'] ?>" ></td>
 <td>Qty: <input name="quantity[]" type="text"  ></td></tr>
<?
} 
echo "</table>";
?>

<input type='submit' value='Submit' />
</form> 

Then on the other page (listbyconsg.php), I have the following so far....

$get_id=$_POST['checkbox']; 
$get_qty=$_POST['quantity']; 

I am unsure then as to how to loop through both these arrays and add information into another table with the something thing like this:

$sql1 = "INSERT INTO newOrder (id, orderQuantity)
VALUES ('$get_id', '$get_qty')"
4

1 回答 1

0

要遍历 PHP 中的数组,您可以执行以下操作:

$count = count($_POST['quantity']);
for($i=0; $i<$count; $i++){
    if(isset($_POST['checkbox'][$i])){
        $checkbox = $_POST['checkbox'][$i];
        $quantity = $_POST['quantity'][$i];
        mysql_query("INSERT INTO newOrder (id, orderQuantity)
            VALUES ($checkbox, $quantity)");
    }
}
于 2013-02-21T23:59:20.310 回答