2015-08-09 18 views
0

我在PHP MySQL的初學者,我有以下形式的圖像類型如何保存所有行的值或僅選定行的字段值的問題: - 字段名稱如: -如何存儲動態生成的表單不同的字段值返回到數據庫PHP的MySQL?

foreach($data as $row){ 
<tr> 
    <td><input type="checkbox" value="$row['ProductID']" name="productID[]" /></td> 
    <td>  <input type="text" value="$row['Quantity']" name="quantity[]" /></td> 
<td><input type="text" value="$row['Price']" name="price[]" /></td> 
</tr> 
} 

enter image description here

1的問題是如何獲得在PHP或jQuery的 唯一入選的行字段值我不知道如何在PHP

回答

1

獲得唯一入選的行字段值如果你想獲得一個LIS

<?php 
    $data[] = array('ProductID'=>123,"Quantity"=>1,"Price"=>"2.00"); 
    $data[] = array('ProductID'=>234,"Quantity"=>2,"Price"=>"1.50"); 
    $data[] = array('ProductID'=>345,"Quantity"=>1,"Price"=>"4.59"); 
    $data[] = array('ProductID'=>456,"Quantity"=>4,"Price"=>"1.99"); 

    foreach($data as $row){ ?> 
    <tr> 
     <td><input type="checkbox" name="product[<?php echo $row['ProductID'];?>][select]" /></td> 
     <td><input type="text" value="<?php echo $row['Quantity']; ?>" name="product[<?php echo $row['ProductID'];?>][qty]" /></td> 
     <td><input type="text" value="<?php echo $row['Price']; ?>" name="product[<?php echo $row['ProductID'];?>][price]" /></td> 
    </tr> 
<?php } 

爲您提供::

// Just loop through the [product] array looking for the 'select' = 'on' 
Array 
(
    [product] => Array 
     (
      [123] => Array 
       (
        [qty] => 1 
        [price] => 2.00 
       ) 

      [234] => Array 
       (
        [select] => on 
        [qty] => 2 
        [price] => 1.50 
       ) 

      [345] => Array 
       (
        [qty] => 1 
        [price] => 4.59 
       ) 

      [456] => Array 
       (
        [qty] => 4 
        [price] => 1.99 
       ) 
     ) 
) 
所有項目用一記是否選擇或不,只是改變你的表單名稱位(如果我明白你在找什麼...)的婷

要獲得所選項目:

if(!empty($_POST['product'])) { 
    foreach($_POST['product'] as $row) { 
      if(!empty($row['select'])) { 
        print_r($row); 
       } 
     } 
} 
+0

感謝您的答覆,但你可以請寫代碼是如何遍歷在S選 –

+0

相同的方式,做表:'的foreach($ _ POST [「產品」]爲$行){... etc.' – Rasclatt

+0

再次感謝你,但請原諒我真的do'not知道如何收集僅選擇行字段值將ü請寫完整的代碼只爲選定的行它可以是一個或多個? –

相關問題