2017-05-02 2 views
0

私はいくつかのフィールドを入力してデータベースに格納しています。私は 新しいボタンを追加して、ユーザーがより多くのデータを保存したい場合は新しい行を追加しましたが、 はテーブルの独自の主キーを使って各行を個別に保存します。以下はphp、mysql、jQueryを使用して各行をプライマリキーでデータベースに個別に保存する方法

新しいボタンを追加するための新しいボタンとjQueryを追加して、テーブルの私のhtmlコードです:

<div class="table-responsive"> 
    <table id="datatable-buttons" class="table table-striped jambo_table bulk_action"> 
    <thead> 
     <tr class="headings"> 
     <th> 
      <input type="checkbox" id="check-all" class="flat"> 
     </th> 
     <th class="column-title">Account</th> 
     <th class="column-title">Debits</th> 
     <th class="column-title">Credits</th> 
     <th class="column-title">Description</th> 
     <th class="column-title">Name</th>       
     <th class="column-title no-link last"><span class="nobr">Action</span> 
     </th> 
     <th class="bulk-actions" colspan="7"> 
      <a class="antoo" style="color:#fff; font-weight:500;">Bulk Actions (<span class="action-cnt"> </span>) <i class="fa fa-chevron-down"></i></a> 
     </th> 
     </tr> 
    </thead>         
    <tbody> 
     <tr class="even pointer"> 
     <td class="a-center "> 
      <input type="checkbox" class="flat" name="table_records"> 
     </td>          
     <td class=" "><select class="form-control" name="journalname"> 
      <option>Choose option</option>     
      <?php 
      $sql = mysqli_query($conn,'SELECT * FROM `chartofaccounts`'); 
      while ($row1 = mysqli_fetch_array($sql)) 
      {?> 
       <option value="<?php echo $row1["name"];?>"><?php echo $row1["name"];?></option> 
      <?php }?> 
     </select></td> 
     <td class=""><input class="form-control" type="text" name="debit" ></td> 
     <td class=" "><input class="form-control" type="text" name="credit"></td> 
     <td class=" "><input class="form-control" type="text" name="descc"></td> 
     <td class=" "><input class="form-control" type="text" name="name"></td>   
     <td class=" last"><a href="#">View</a> 
     </td> 
     </tr>       
    </tbody>       
    </table> 
    <button type="button" id="add">Add New</button> 
</div> 

jQueryの新しい行を追加する:

<script type="text/javascript"> 
     $("#add, .check ").click(function() { 
     $('#datatable-buttons tbody>tr:last') 
     .clone(true) 
     .insertAfter('#datatable-buttons 
     tbody>tr:last').find('input').each(function(){ 
     $(this).val(''); 
     }); 
    }); 
</script> 
+0

複数入力に同じ名前を使用することはできませんので、この JYoThI

+0

のように配列名= "debit [私は配列とimplode関数を使用していますが、私の条件ごとに動作していません。現在は、debit1、debit2、debit3のように1行に格納されています。 3つの値はすべて、異なる主キーを持つ異なる行になければなりません。 –

答えて

0

あなたはidカラムを作成することができますデータベーステーブル。プライマリキーと自動インクリメント(mysqlを使用している場合はphpmyadminのAIオプション)として設定する必要があります。他のデータを格納するだけで、ID列が自動的にその値を取り、各行ごとに一意になります。

+0

これは解決策ではありません。 –

関連する問題