Importing data from php database into an existing table to add two more additional columns framework = php codeignitor
Get the solution ↓↓↓I have added these two additional columns on the right called "Note" and "Staff Note" and I have being trying to fill them with the data from a table in my phpmyadmin
I have also redacted the customer names and biller names in column 3 and 4 for privacy
this is how I added the columns to the view header in the image attached below
This is the code I used to add the two columns so far
<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>
I can not find the dataloop how the rest of the columns seem to be populated like like this
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");
I have tried adding the additional column_number for instance column_number 11, and column_number 12, but not sure which mRender to initialise them with
Any ideas how I can grab the data I know exists in a phpmyadmin table called sales which the row structure are titled the same as the columns I want them to go into eg, Notes and Staff Note to show up in the table in the image above
the table looks like it is referenced as #POSData in the above code when I search for this #POSData I can only find this code below and I don't understand how this is structured or what this numbers in the code below reference to
#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%; }
In summary my question is simply how can I add the data to populate these two last columns which I know exists in my php database table Called sales
Answer
Solution:
I ended up working this out,
I added the table row name into the data loop of the data table lookup into the relevant php in the admin>view>controller>*.php
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string deprecated
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.