Using own variable from PHP, help please...
Using own variable from PHP, help please...
Hello,
I have a problem with my own variable from PHP, how I using it ?
That is my code from PHP, where I variable create :
[code]
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ '; $sDetail .= '"DetailData": [ ';
while ( $aRow = $rResult->fetch_array() )
{
$sOutput .= "[";
$sOutput .= '"",';
$sOutput .= '"'.addslashes($aRow['id_sho']).'",';
$sOutput .= '"'.addslashes($aRow['name']).'",';
$sOutput .= '"'.addslashes($aRow['url_feed']).'",';
$sOutput .= "],";
// shop detail // my variable $sDetail
$sDetail .= "[";
$sDetail .= '"'.addslashes($aRow['email']).'",';
$sDetail .= '"'.addslashes($aRow['company']).'",';
$sDetail .= '"'.addslashes($aRow['city']).'",';
$sDetail .= '"'.addslashes($aRow['street']).'",';
$sDetail .= '"'.addslashes($aRow['psc']).'",';
$sDetail .= '"'.addslashes($aRow['ic']).'",';
$sDetail .= '"'.addslashes($aRow['dic']).'",';
$sDetail .= '"'.addslashes($aRow['operator1']).'",';
$sDetail .= '"'.addslashes($aRow['phone']).'",';
$sDetail .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] ';
$sDetail = substr_replace( $sDetail, "", -1 );
$sOutput .= ",".$sDetail;
$sOutput .= '] }';
echo $sOutput;
[/code]
My variable is $soutput and add for $sOutput.
Echo write this :
[code]
{"sEcho": 1, "iTotalRecords": 3, "iTotalDisplayRecords": 3,
"aaData": [
["","1","asa","http://www.shop2.sk",],
["","2","asa","http://www.shop2.sk",],
["","3","Shopixo","http://www.shopixo.xo-studio.cz/XML/feed-seznam.xml",]
],
"DetailData": [
["bar714@gmail.com","XO-Studio","Ostrava","Kuku?
I have a problem with my own variable from PHP, how I using it ?
That is my code from PHP, where I variable create :
[code]
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ '; $sDetail .= '"DetailData": [ ';
while ( $aRow = $rResult->fetch_array() )
{
$sOutput .= "[";
$sOutput .= '"",';
$sOutput .= '"'.addslashes($aRow['id_sho']).'",';
$sOutput .= '"'.addslashes($aRow['name']).'",';
$sOutput .= '"'.addslashes($aRow['url_feed']).'",';
$sOutput .= "],";
// shop detail // my variable $sDetail
$sDetail .= "[";
$sDetail .= '"'.addslashes($aRow['email']).'",';
$sDetail .= '"'.addslashes($aRow['company']).'",';
$sDetail .= '"'.addslashes($aRow['city']).'",';
$sDetail .= '"'.addslashes($aRow['street']).'",';
$sDetail .= '"'.addslashes($aRow['psc']).'",';
$sDetail .= '"'.addslashes($aRow['ic']).'",';
$sDetail .= '"'.addslashes($aRow['dic']).'",';
$sDetail .= '"'.addslashes($aRow['operator1']).'",';
$sDetail .= '"'.addslashes($aRow['phone']).'",';
$sDetail .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] ';
$sDetail = substr_replace( $sDetail, "", -1 );
$sOutput .= ",".$sDetail;
$sOutput .= '] }';
echo $sOutput;
[/code]
My variable is $soutput and add for $sOutput.
Echo write this :
[code]
{"sEcho": 1, "iTotalRecords": 3, "iTotalDisplayRecords": 3,
"aaData": [
["","1","asa","http://www.shop2.sk",],
["","2","asa","http://www.shop2.sk",],
["","3","Shopixo","http://www.shopixo.xo-studio.cz/XML/feed-seznam.xml",]
],
"DetailData": [
["bar714@gmail.com","XO-Studio","Ostrava","Kuku?
This discussion has been closed.
Replies
What you need to do is pass back all of the information as sOutput since this is the main way to get information into DataTables. From there, you should make these columns hidden: this ones which contain the information that you don't want to display to the user, but need for the rendering for the "details". So I think you are fairly close to being there - just copy the example closely, and then set bVisible for the columns you want to hide.
There is another way to do it if you want - which doesn't involve hidden columns, but does require array manipulation. Using fnServerData you could get the data back and then store it in a javascript object which will be used for display later on. A little more tricky, but possible if you prefer this method.
Regards,
Allan
Thank you for your reply
So I tried the first method failed, and I hide columns, enclose the code:
[code]
oTable = $('#shops').dataTable({
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sAjaxSource": getRoot()+"scripts/class/show-shops.ajax.php",
"aoColumns": [
{ "sClass": "center", "bSortable": false, },null,null,{ "sType": "html" }, // first 4 displaying
{ "bVisible": false }, // other using for detail
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false }
],
"fnDrawCallback": fnOpenClose,
"oLanguage": {
"sProcessing": "Pracujem...",
"sLengthMenu": "Zobraz _MENU_ z
And yet I have an idea to the new version, it would be good if they can register the variables that would be created, as I saw at first contribution (Details) and then use those in the DataTable.
Thanks very much