How Parsing javascript vars to PHP in Datatable
How Parsing javascript vars to PHP in Datatable
ANdra
Posts: 2Questions: 1Answers: 0
Hi all, i'm new in datatables and sorry for my bad english.
i really need your help to help solve my problem, i;m stuck on this.
So, my code is all in one page :
$( function () {
var oTable;
function fnFormatDetails( nTr ) {
var aData = oTable.fnGetData(nTr);
sOut = "<?php foreach($this->m_rumah_sakit->getStyleAndCount(280)->result() as $style){
echo $style->keterangan; ?>
<br /> 1. Yes : ( <i><?php echo ($style->yes)?$style->yes:'0'; ?> Ulasan </i>)
<br /> 2. No : ( <i><?php echo ($style->no)?$style->no:'0'; ?> Ulasan</i> )
<br /> 3. Not Sure : ( <i><?php echo ($style->not_sure)?$style->not_sure:'0'; ?> Ulasan</i> ) <br /><?php } ?>";
return sOut;
}
$(document).ready ( function() {
oTable = $('#tSortable').dataTable({
"bProcessing": true,
"bServerSide": true,
"aaSorting": [[1,'asc']],
"oLanguage": {"sProcessing": "<img src=" + vars.loader + ">"},
//"sAjaxSource": "../details_col.php",
"sAjaxSource" : base + "cms-ajax-data",
"fnServerParams" : function ( aoData ) {
aoData.push(
{ "name": "p", "value" : "" },
{ "name": "hRating", "value" : "hospital" }
,{ "name": "c", "value" : vars.column }
,{ "name": "iC", "value" : vars.indexColumn }
,{ "name": "t", "value" : vars.table }
,{ "name": "w", "value" : vars.where }
,{ "name": "imp", "value" : vars.implode }
);
},
"aoColumnDefs": [{"bSortable":false,"bSearchable":false, "sClass": "hidden", "aTargets":[1]}]
});
$('#tSortable tbody td img').live('click',function(){
var nTr = this.parentNode.parentNode;
if(this.src.match('details_close')){
this.src = "..//details_open.png";
oTable.fnClose(nTr);
}else
this.src = "../details_close.png";
oTable.fnOpen(nTr,fnFormatDetails(nTr),'details');
}
});
});
And all works like charms! the only problem is : how i can get variable aData[2] in PHP script?
i mean, how to call it like this in my PHP code :
foreach($this->m_rumah_sakit->getStyleAndCount("+aData[2]+")->result();
Hope u understand what i mean. Thanks for any advise
This discussion has been closed.
Answers
The PHP is executed at the server - i.e. before the Javascript. There is simply no way to execute PHP at the client-side when that function itself is executed.
You have two options:
Allan
Thanks for your reply allan, so, can you tell me how i suppose to do next if i choose to formating in javascript.
I've try to make an ajax request but still does't works:
It just give me the empty PHP variabel
And from now on, i think the option 2 will be my last choice :D
thanks
You'r
$.ajax
call doesn't appear to have aurl
option. You probably need one.Allan