首页 > 解决方案 > 将 php 数据库中的数据导入现有表以添加另外两个额外的列 framework = php codeignitor

问题描述

我在右侧添加了这两个名为“Note”和“Staff Note”的附加列,我试图用我的 phpmyadmin 中的表中的数据填充它们

出于隐私考虑,我还在第 3 列和第 4 列中编辑了客户姓名和开票人姓名

这就是我将列添加到下图中的视图标题的方式

当前表

这是到目前为止我用来添加两列的代码

    <div class="box-content">
    <div class="row">
        <div class="col-lg-12">
            <p class="introtext"><?= lang('list_results'); ?></p>

            <div class="table-responsive">
                <table id="POSData" class="table table-bordered table-hover table-striped">
                    <thead>
                    <tr>
                        <th style="min-width:20px; width: 20px; text-align: center;">
                            <input class="checkbox checkft" type="checkbox" name="check"/>
                        </th>
                        <th><?= lang('date'); ?></th>
                        <th><?= lang('reference_no'); ?></th>
                        <th><?= lang('biller'); ?></th>
                        <th><?= lang('customer'); ?></th>
                        <th><?= lang('grand_total'); ?></th>
                        <th><?= lang('paid'); ?></th>
                        <th><?= lang('balance'); ?></th>
                        <th><?= lang('sale_status'); ?></th>
                        <th><?= lang('payment_status'); ?></th>
                        <th style="width:80px; text-align:center;"><?= lang('actions'); ?></th>
                        <th><?= lang('note'); ?></th>
                        <th><?= lang('staff_note'); ?></th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td colspan="12" class="dataTables_empty"><?= lang('loading_data'); ?></td>
                    </tr>
                    </tbody>
                    <tfoot class="dtFilter">
                    <tr class="active">
                        <th style="min-width:20px; width: 20px; text-align: center;">
                            <input class="checkbox checkft" type="checkbox" name="check"/>
                        </th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th><?= lang('grand_total'); ?></th>
                        <th><?= lang('paid'); ?></th>
                        <th><?= lang('balance'); ?></th>
                        <th class="defaul-color"></th>
                        <th class="defaul-color"></th>
                        <th style="width:60px; text-align:center;"><?= lang('actions'); ?></th>
                        <th></th>
                        <th></th>
                    </tr>
                    </tfoot>
                </table>

我找不到数据循环,其余列似乎是这样填充的

oTable = $('#POSData').dataTable({
        "aaSorting": [[1, "desc"], [2, "desc"]],
        "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "<?= lang('all') ?>"]],
        "iDisplayLength": <?= $Settings->rows_per_page ?>,
        'bProcessing': true, 'bServerSide': true,
        'sAjaxSource': '<?= admin_url('pos/getSales' . ($warehouse_id ? '/' . $warehouse_id : '')) ?>',
        'fnServerData': function (sSource, aoData, fnCallback) {
            aoData.push({
                "name": "<?= $this->security->get_csrf_token_name() ?>",
                "value": "<?= $this->security->get_csrf_hash() ?>"
            });
            $.ajax({'dataType': 'json', 'type': 'POST', 'url': sSource, 'data': aoData, 'success': fnCallback});
        },
        'fnRowCallback': function (nRow, aData, iDisplayIndex) {
            var oSettings = oTable.fnSettings();
            nRow.id = aData[0];
            nRow.className = "receipt_link";
            return nRow;
        },
        "aoColumns": [{
            "bSortable": false,
            "mRender": checkbox
        }, {"mRender": fld}, null, null, null, {"mRender": currencyFormat}, {"mRender": currencyFormat}, {"mRender": balance}, {"mRender": row_status}, {"mRender": pay_status}, {"bSortable": false}],
        "fnFooterCallback": function (nRow, aaData, iStart, iEnd, aiDisplay) {
            var gtotal = 0, paid = 0, bal = 0;
            for (var i = 0; i < aaData.length; i++) {
                gtotal += parseFloat(aaData[aiDisplay[i]][5]);
                paid += parseFloat(aaData[aiDisplay[i]][6]);
                bal += parseFloat(balance(aaData[aiDisplay[i]][7], 'number'));
            }
            var nCells = nRow.getElementsByTagName('th');
            nCells[5].innerHTML = currencyFormat(parseFloat(gtotal));
            nCells[6].innerHTML = currencyFormat(parseFloat(paid));
            nCells[7].innerHTML = currencyFormat(parseFloat(bal));
        }
    }).fnSetFilteringDelay().dtFilter([
      {column_number: 1, filter_default_label: "[<?=lang('date');?> (yyyy-mm-dd)]", filter_type: "text", data: []},
      {column_number: 2, filter_default_label: "[<?=lang('reference_no');?>]", filter_type: "text", data: []},
      {column_number: 3, filter_default_label: "[<?=lang('biller');?>]", filter_type: "text"},
      {column_number: 4, filter_default_label: "[<?=lang('customer');?>]", filter_type: "text", data: []},
      {column_number: 8, filter_default_label: "[<?=lang('sale_status');?>]", filter_type: "text", data: []},
      {column_number: 9, filter_default_label: "[<?=lang('payment_status');?>]", filter_type: "text", data: []},

    ], "footer");

我尝试添加额外的 column_number,例如 column_number 11 和 column_number 12,但不确定使用哪个 mRender 初始化它们

我如何获取我知道的数据存在于名为 sales 的 phpmyadmin 表中的任何想法,其中行结构的标题与我希望它们进入的列相同,例如,Notes 和 Staff Note 显示在上图中的表中

当我搜索此#POSData 时,该表看起来在上面的代码中被引用为#POSData 我只能在下面找到此代码,而且我不明白它的结构或下面代码中的这个数字引用了什么

    #POSData td:nth-child(6), #POSData td:nth-child(7), #POSData tfoot th:nth-child(6), #POSData tfoot th:nth-child(7), #POSData td:nth-child(8), #POSData tfoot th:nth-child(8) { width: 10% !important; text-align: right; }
#POSData td:nth-child(9), #POSData tfoot th:nth-child(9) { width: 12%; }

总之,我的问题只是如何添加数据来填充我知道存在于我的 php 数据库表中的最后两个列,称为 sales

标签: phpmultiple-columnsdatatables-1.10

解决方案


我最终解决了这个问题,

我在 admin>view>controller>*.php 中将表行名称添加到数据表查找到相关 php 的数据循环中


推荐阅读