Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php、mysql和jQuery在数据库中分别存储每一行及其主键_Php_Jquery_Mysql_Html Table_Row - Fatal编程技术网

如何使用php、mysql和jQuery在数据库中分别存储每一行及其主键

如何使用php、mysql和jQuery在数据库中分别存储每一行及其主键,php,jquery,mysql,html-table,row,Php,Jquery,Mysql,Html Table,Row,我使用table输入一些字段并将其存储在db中。我用了Add “新建”按钮,用于添加新行,前提是用户希望存储更多数据,但我希望 在表中单独存储每一行及其主键 下面是我的带有“添加新按钮”和“添加新按钮”的jQuery的表格的html代码: <div class="table-responsive"> <table id="datatable-buttons" class="table table-striped jambo_table bulk_action">

我使用table输入一些字段并将其存储在db中。我用了Add “新建”按钮,用于添加新行,前提是用户希望存储更多数据,但我希望 在表中单独存储每一行及其主键

下面是我的带有“添加新按钮”和“添加新按钮”的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>

$(“#添加,.check”)。单击(函数(){
$(“#数据表按钮tbody>tr:last”)
.clone(真)
.insertAfter(“#数据表按钮
tbody>tr:last').find('input').each(函数(){
$(this.val(“”);
});
});

您可以在数据库表中创建id列。您需要将其设置为主键和自动增量(如果您使用的是mysql,则phpmyadmin中的AI选项)。您只需要存储其他数据,id列将自动获取其值,该值对于每一行都是唯一的

您不能对多个输入使用相同的名称,所以只需使用as-array name=“debit[]”像这样,我使用了数组和内爆函数,但没有按照我的条件工作。目前它像debit1、debit2、debit3一样存储在单行中。这三个值都应该位于不同的行中,主键不同。