I get stuck with my code. If you know about it, please respond to this question, cause I very need your help.
I have 2 tables (proposal and surveyor).
Proposal field :
proposal_id, proposal_name, surveyor_proposal
Example row : ('1', 'this is proposal name', '3,18,22')
As you can see, this is have 3 surveyor id separated by comma)
Surveyor field :
surveyor_id, surveyor_name
Example row :
- ('3', 'Randy')
- ('18', 'Bella')
- ('22', 'Zidan')
! here it is, I want to print out Randi, Bella, and Zidan in the view table
Model.php
:
function get_all_datatables($x) {
$this->datatables->select('proposal_name, surveyor_name');
$this->datatables->from('proposal');
$this->datatables->join('surveyor','surveyor_id = surveyor_proposal','left');
return $this->datatables->generate();
}
Controller.php
:
function get_data_json($x) { //get product data and encode to be JSON object
header('Content-Type: application/json');
echo $this->m_bl->get_all_datatables($x);
}
View.php
:
$("#table").dataTable({
initComplete: function() {
var api = this.api();
$('#table_filter input')
.off('.DT')
.on('input.DT', function() {
api.search(this.value).draw();
});
},
oLanguage: {
sProcessing: "loading..."
},
processing: true,
serverSide: true,
ajax: {"url": "<?= base_url('dashboard/bl/get_data_json/'.$uri); ?>", "type": "POST"},
{"data": "proposal_name"},
{"data": "surveyor_name"},
rowCallback: function(row, data, iDisplayIndex) {
var info = this.fnPagingInfo();
var page = info.iPage;
var length = info.iLength;
$('td:eq(0)', row).html();
}
});
Update!
I've been add 1 table junction, the fields is :
proposal_id_junction, surveyor_id_junction
Example Value :
- ('1','3') --> as Randy
- ('1','18') --> as Bella
- ('1','22') --> as Zidan
And i update my table join :
$this->datatables->join('junction','proposal_id_junction = proposal_id','left');
$this->datatables->join('surveyor','surveyor_id = surveyor_id_junction','left');
But, thats showing same proposal and different surveyor name, like this :
'this is proposal name','Randy'
'this is proposal name','Bella'
'this is proposal name','Zidan'
I want to thats view like this :
'this is proposal name','Randy, Bella, Zidan'
Please help.