如何使用Codeiginter从动态创建的表中的数据库中获取数据

时间:2018-10-17 04:59:12

标签: javascript php html codeigniter

<table class="table table-bordered table-striped table-xxs" id="tb3" name="tb3">
    <thead>
        <tr>
            <th><a href="javascript:void(0);" id="multi" name="multiplerows" title="Add More Person"></a></th>
            <th>Product Code</th>
            <th>Product Name</th>
            <th>Qty</th>
            <th>Rate</th>
            <th>Amount</th>


        </tr>
    </thead>
    <tbody>
        <tr >
            <td><a href='javascript:void(0);' class='remove3'><span class='glyphicon glyphicon-remove'></span></a></td>

            <td>

            <input style="width:80px" type="text" id="Product_Code"  class="form-control input-xs Product_Code "  onkeyup="fetch()" value="<?php echo $r->Product_Code; ?>" name="Product_Code[]" required></td>

            <td ><input style="width:300px" type="text" id="Product_Name" class="form-control input-xs" value="<?php echo $r->Prdtname; ?>" name = "Prdtname[]"  value=""> </td>


            <td><input style="width:80px" type="text" id="Qty"  class="form-control input-xs"  value="<?php echo $r->Qty; ?>" name="Qty[]" required></td>

            <td><input style="width:100px" type="text" id="Rate"  class="form-control input-xs" value="<?php echo $r->rate; ?>" name="rate[]" required></td>

            <td><input style="width:150px" type="text" id="Value" class="form-control input-xs" value="<?php echo $r->amount; ?>" name="amount[]" ></td>


        <th><a href="javascript:void(0);" id="addMore3" name= addmore title="Add More Person"><span class="glyphicon glyphicon-plus"></span></a></th>

        </tr>
    </tbody>
</table>

此表代码。...

<script>
$(document).ready(function (){
$('#addMore3').on('click', function() {

  var data = $("#tb3 tr:eq(1)").clone(true).appendTo("#tb3");
          data.find("input").val('');

 });
 $(document).on('click', '.remove3', function() {
     var trIndex = $(this).closest("tr").index();
        if(trIndex>0) {
         $(this).closest("tr").remove();
       } else {
         alert("Sorry!! Can't remove first row!");
       }
  });

});

</script>

这是用于通过单击“ +”事件创建表的javascript代码。

我的prblm是如何从此自动表中的数据库显示中获取数据。

1 个答案:

答案 0 :(得分:1)

您应该能够使用ajax调用来做到这一点。

在使用codeigniter时-

查看:编写您的Ajax和表生成代码。 控制器::获取ajax请求并将其传递给模式。 模式::从数据库中获取数据。

您应该返回对象数组以进行查看,然后只需解析数据并生成表。 如果您不想编写表代码和Ajax,则可以使用数据表插件