recursive function
recursive function
jemz
Posts: 131Questions: 40Answers: 1
I have recursive function
`
public function myFunRec($parent,$level,$rs,$rec = array()){
// query statement here...
$rec = $cmd->fetchAll(PDO::FETCH_ASSOC);
while ( $row = $cmd->fetch(PDO::FETCH_ASSOC)) {
$rec = $this->myFunRec($row['uid'], $level + 1,$rs,$rec);
}
$datarecord = array('draw'=>$draw,
'recordsTotal'=>$rs,
'recordsFiltered'=>$rs,
'data'=>$rec
);
$cmd = null;
return json_encode($datarecord);
}
`
it works if I have like this ,without the while loop,but it will not perform recursive.
`
public function myFunRec($parent,$level,$rs,$rec = array()){
// query statement here....
$rec = $cmd->fetchAll(PDO::FETCH_ASSOC);
$datarecord = array('draw'=>$draw,
'recordsTotal'=>$rs,
'recordsFiltered'=>$rs,
'data'=>$rec
);
$cmd = null;
return json_encode($datarecord);
`
here is my datatables client
`
$('#showlist').dataTable({
"autoWidth":true,
"searching":false,
"processing": true,
"serverSide": true,
"start": 0,
"ajax": {
url:"toOther.php"
},
"deferRender": true,
"columns": [
{ "data": "id"},
{ "data": "FULLNAME"},
{ "data": "status"}
]
});
Is it possible to use recursive in datatables ?
Thank you in advance
This discussion has been closed.
Answers
It looks like the recursion is in PHP rather than in DataTables (which is a Javascript library) - however, yes, it should be quite possible to use recursion assuming that the server returns the JSON data needed by DataTables. DataTables doesn't really care how the server gets the data to be honest, it just needs the server to get it!
Allan
Ok, allan thank you for the quick reply...actually i get working with this if i don't use the datatables...I can make my function recursive works ok...but using datatables i get in trouble I'll just try to debug this and should I just my code to make this works in datatables.I hope you can help me too :),to make this work.
Thank you in advance.
I don't really understand why enabling DataTables on the client-side would make any difference to the server-side PHP. Can you link me to the page so I can take a look please? Also it would be useful if you could post the full PHP.
Allan