Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

gabrielfalieri

retorno de json_encode inválido

Recommended Posts

Boa tarde galera do imarsters.
Tenho uma classezinha que faz retorno do php em json

<?php
/* Database connection start */


$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

/* Database connection end */


// storing  request (ie, get/post) global array to a variable
$requestData= $_REQUEST;


$columns = array(
// datatable column index  => database column name
    0 =>'razao_social',
    1 =>'nome',
    2 => 'cargo',
    3 => 'tel_comercial1',
    4 => 'tel_celular1',
    5 => 'email1',
    6 => 'id_resp'
);




// getting total number records without any search
$sql.="SELECT razao_social,nome,cargo,tel_comercial1,tel_celular1,email1,id_resp";
$sql.=" FROM responsibles_view";
$query=mysqli_query($conn, $sql) or die("Erro");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.


$sql = "SELECT razao_social,nome,cargo,tel_comercial1,tel_celular1,email1,id_resp ";
$sql.=" FROM responsibles_view WHERE 1 = 1";

if(!empty($requestData['search']['value'])){
    $sql.=" AND razao_social LIKE '%".$requestData['search']['value']."%'".
        "OR nome LIKE '%".$requestData['search']['value']."%'".
        "OR cargo LIKE '%".$requestData['search']['value']."%'".
        "OR tel_comercial1 LIKE '%".$requestData['search']['value']."%'".
        "OR tel_celular1 LIKE '%".$requestData['search']['value']."%'".
        "OR email1 LIKE '%".$requestData['search']['value']."%'";
        //"OR id_resp LIKE '%".$requestData['search']['value']."%'";
}
/*
if(!empty($requestData['columns'][15]['search']['value'])){
    $sql.=" AND razao_social LIKE '".$requestData['columns'][15]['search']['value']."%' ";
}*/

$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.

$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."   LIMIT ".$requestData['start']." ,".$requestData['length']."   ";  // adding length

$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");

$data = array();
while( $row=mysqli_fetch_array($query) ) {  // preparing an array
    $nestedData=array();

    $nestedData[] = $row["razao_social"];
    $nestedData[] = $row["nome"];
    $nestedData[] = $row["cargo"];
    $nestedData[] = $row["tel_comercial1"];
    $nestedData[] = $row["tel_celular1"];
    $nestedData[] = $row["email1"];
    $nestedData[] = "<a href='detail-license.php?id=".$row['id_resp']."'><button class='btn btn-success'><i class='fa fa-list'></i> Detalhes</button></a>";

    $data[] = $nestedData;
}

$json_data = array(
    "draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
    "recordsTotal"    => intval( $totalData ),  // total number of records
    "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
    "data"            => $data   // total data array
);

echo json_encode($json_data);  // send data as json format


Uma view com os campos selecionados 'razao_social','nome','cargo',tel_comercial1',tel_celular1',email1',id_resp' e está dando retorno inválido. Quando eu abro o chrome, diz que this request has no response data available

Compartilhar este post


Link para o post
Compartilhar em outros sites

this request has no response data available

Isso é claro, se não está retornando nada o json é inválido, verifique isto primeiro então.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Acontece que eu coloco esse certinho, ai só mudo os campos com o que estou listando na minha view, ai da pau

<?php
/* Database connection start */


$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

/* Database connection end */


// storing  request (ie, get/post) global array to a variable
$requestData= $_REQUEST;


$columns = array(
// datatable column index  => database column name
    0 =>'razao_social',
    1 =>'organization_name',
    2 => 'organization_type',
    3 => 'edition',
    4 => 'licensed_version',
    5 => 'issued_date',
    6 => 'updates_expiry_date',
    7 => 'support_expiry_date',
    8 => 'advanced_clients_licensed',
    9 => 'users_licensed',
    10 => 'id_license'
);




// getting total number records without any search
$sql = "SELECT razao_social,organization_name, organization_type,edition, licensed_version,issued_date,updates_expiry_date,support_expiry_date,advanced_clients_licensed,users_licensed,id_license ";
$sql.=" FROM license_view";
$query=mysqli_query($conn, $sql) or die("Erro");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.




$sql = "SELECT razao_social,organization_name, organization_type,edition, licensed_version,issued_date,updates_expiry_date,support_expiry_date,advanced_clients_licensed,users_licensed,id_license  ";
$sql.=" FROM license_view WHERE 1 = 1";


if( !empty($requestData['columns'][0]['search']['value']) || !empty($requestData['columns'][1]['search']['value'])) { //age
    if ($requestData['columns'][1]['search']['value'] < 1000) {
        $sql .= " AND users_licensed BETWEEN " . $requestData['columns'][0]['search']['value'] . " AND " . $requestData['columns'][1]['search']['value'];
    }
    else{
        $sql.=" AND ( users_licensed < '".$requestData['columns'][0]['search']['value'] ."' OR  users_licensed > '". $requestData['columns'][1]['search']['value']."' ) ";
    }
}
if(!empty($requestData['columns'][2]['search']['value'])){
    $sql.=" AND licensed_version LIKE '".$requestData['columns'][2]['search']['value']."%' ";
}
if(!empty($requestData['columns'][3]['search']['value']) && (!empty($requestData['columns'][4]['search']['value']))){
    $sql.=" AND organization_type LIKE  '".$requestData['columns'][3]['search']['value']."%' OR	organization_type LIKE  '".$requestData['columns'][4]['search']['value']."%'" ;
}
else if(!empty($requestData['columns'][3]['search']['value']) && (!empty($requestData['columns'][5]['search']['value']))){
    $sql.=" AND organization_type LIKE  '".$requestData['columns'][3]['search']['value']."%' OR organization_type LIKE  '".$requestData['columns'][5]['search']['value']."%'" ;
}
else if(!empty($requestData['columns'][4]['search']['value']) && !empty($requestData['columns'][5]['search']['value'])){
    $sql.=" AND organization_type LIKE  '".$requestData['columns'][4]['search']['value']."%' OR organization_type LIKE '".$requestData['columns'][5]['search']['value']."%'" ;
}
else if(!empty($requestData['columns'][3]['search']['value']) && !empty($requestData['columns'][4]['search']['value']) && !empty($requestData['columns'][5]['search']['value'])){
    $sql.=" AND organization_type LIKE  '".$requestData['columns'][3]['search']['value']."%' OR organization_type LIKE  '".$requestData['columns'][4]['search']['value']."%' OR organization_type LIKE '".$requestData['columns'][5]['search']['value']."%'"  ;
}
else if(!empty($requestData['columns'][3]['search']['value'])){
    $sql.=" AND organization_type LIKE  '".$requestData['columns'][3]['search']['value']."%'" ;
}
else if(!empty($requestData['columns'][4]['search']['value']) ){
    $sql.=" AND organization_type LIKE  '".$requestData['columns'][4]['search']['value']."%'";
}
else if(!empty($requestData['columns'][5]['search']['value'])){
    $sql.=" AND organization_type LIKE '".$requestData['columns'][5]['search']['value']."%'";
}

if(!empty($requestData['columns'][6]['search']['value']) && empty($requestData['columns'][7]['search']['value'])) {
    $sql .= " AND  edition LIKE '" . $requestData['columns'][6]['search']['value'] . "%' ";
}

else if(!empty($requestData['columns'][7]['search']['value'])  && empty($requestData['columns'][6]['search']['value'])) {
    $sql .= " AND  edition LIKE '" . $requestData['columns'][7]['search']['value'] . "%' ";
}
else if(!empty($requestData['columns'][6]['search']['value']) && !empty($requestData['columns'][7]['search']['value'])) {
    $sql .= " AND  edition LIKE '" . $requestData['columns'][6]['search']['value'] . "%'  OR  edition LIKE '" . $requestData['columns'][6]['search']['value']."%'";
}


if(!empty($requestData['columns'][8]['search']['value']) && !empty($requestData['columns'][11]['search']['value']) && !empty($requestData['columns'][12]['search']['value'])){
    $sql .= " AND issued_date BETWEEN '".$requestData['columns'][11]['search']['value']."' AND '".$requestData['columns'][12]['search']['value']."'";
}



if(!empty($requestData['columns'][13]['search']['value']) || !empty($requestData['columns'][14]['search']['value'])){
    $value = $requestData['columns'][13]['search']['value'];
    if($value === 'n'){
        $sql.="AND advanced_clients_licensed > 1";
    }
    else{
        $sql.="AND advanced_clients_licensed < 1";
    }
}

if(!empty($requestData['search']['value'])){
    $sql.=" AND razao_social LIKE '%".$requestData['search']['value']."%'".
        "OR organization_name LIKE '%".$requestData['search']['value']."%'".
        "OR organization_type LIKE '%".$requestData['search']['value']."%'".
        "OR edition LIKE '%".$requestData['search']['value']."%'".
        "OR licensed_version LIKE '%".$requestData['search']['value']."%'".
        "OR issued_date LIKE '%".$requestData['search']['value']."%'".
        "OR updates_expiry_date LIKE '%".$requestData['search']['value']."%'".
        "OR support_expiry_date LIKE '%".$requestData['search']['value']."%'".
        "OR advanced_clients_licensed LIKE '%".$requestData['search']['value']."%'".
        "OR users_licensed LIKE '%".$requestData['search']['value']."%'".
        "OR id_license LIKE '%".$requestData['search']['value']."%'";
}
if(!empty($requestData['columns'][15]['search']['value'])){
    $sql.=" AND razao_social LIKE '".$requestData['columns'][15]['search']['value']."%' ";
}
$query=mysqli_query($conn, $sql) or die("Erro:".mysqli_error($query));

$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.

$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."   LIMIT ".$requestData['start']." ,".$requestData['length']."   ";  // adding length

$query=mysqli_query($conn, $sql) or die("Erro:".mysqli_error($query));




$data = array();
while( $row=mysqli_fetch_array($query) ) {  // preparing an array
    $nestedData=array();

    $nestedData[] = $row["razao_social"];
    $nestedData[] = $row["organization_name"];
    $nestedData[] = $row["organization_type"];
    $nestedData[] = $row["edition"];
    $nestedData[] = $row["licensed_version"];
    $nestedData[] = date("d/m/Y",strtotime($row["issued_date"]));
    $nestedData[] = date("d/m/Y",strtotime($row["support_expiry_date"]));
    $nestedData[] = date("d/m/Y",strtotime($row["updates_expiry_date"]));
    $nestedData[] = $row["advanced_clients_licensed"];
    $nestedData[] = $row["users_licensed"];
    $nestedData[] = "<a href='detail-license.php?id=".$row['id_license']."'><button class='btn btn-success'><i class='fa fa-list'></i> Detalhes</button></a>";

    $data[] = $nestedData;
}



$json_data = array(
    "draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
    "recordsTotal"    => intval( $totalData ),  // total number of records
    "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
    "data"            => $data   // total data array
);

echo json_encode($json_data);  // send data as json format



Compartilhar este post


Link para o post
Compartilhar em outros sites

Agora

<?php
/* Database connection start */


$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

/* Database connection end */


// storing  request (ie, get/post) global array to a variable
$requestData= $_REQUEST;


$columns = array(
// datatable column index  => database column name
    0 =>'razao_social',
    1 =>'nome',
    2 => 'cargo',
    3 => 'tel_comercial1',
    4 => 'tel_celular1',
    5 => 'email1',
    6 => 'id_resp',
    7 => '_ativo'
);





$sql = "SELECT razao_social,nome, cargo,tel_comercial1, tel_celular1,email1,id_resp ";
$sql.=" FROM responsibles_view";
$query=mysqli_query($conn, $sql) or die("Erro");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.

$sql = "SELECT razao_social,nome, cargo,tel_comercial1, tel_celular1,email1,id_resp ";
$sql.=" FROM responsibles_view WHERE 1 = 1";



if(!empty($requestData['search']['value'])){
    $sql.=" AND razao_social LIKE '%".$requestData['search']['value']."%'".
        "OR nome LIKE '%".$requestData['search']['value']."%'".
        "OR cargo LIKE '%".$requestData['search']['value']."%'".
        "OR tel_comercial1 LIKE '%".$requestData['search']['value']."%'".
        "OR tel_celular1 LIKE '%".$requestData['search']['value']."%'".
        "OR email1 LIKE '%".$requestData['search']['value']."%'".
        "OR id_resp LIKE '%".$requestData['search']['value']."%'";
}

$query=mysqli_query($conn, $sql) or die("Erro:".mysqli_error($conn));
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."   LIMIT ".$requestData['start']." ,".$requestData['length']."   ";  // adding length
$query=mysqli_query($conn, $sql) or die("Erro:".mysqli_error($conn));




$data = array();
while( $row=mysqli_fetch_array($query) ) {  // preparing an array
    $nestedData=array();

    $nestedData[] = $row["razao_social"];
    $nestedData[] = $row["nome"];
    $nestedData[] = $row["cargo"];
    $nestedData[] = $row["tel_comercial1"];
    $nestedData[] = $row["tel_celular1"];
    $nestedData[] = $row["email1"];
    $nestedData[] = $row["id_resp"];

    $data[] = $nestedData;
}



$json_data = array(
    "draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
    "recordsTotal"    => intval( $totalData ),  // total number of records
    "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
    "data"            => $data   // total data array
);

echo die(json_encode($json_data));  // send data as json format



Está assim

Compartilhar este post


Link para o post
Compartilhar em outros sites
$nestedData = array();
while( $row=mysqli_fetch_array($query) ) {  // preparing an array

    $nestedData[] = $row["razao_social"];
    $nestedData[] = $row["organization_name"];
    $nestedData[] = $row["organization_type"];
    $nestedData[] = $row["edition"];
    $nestedData[] = $row["licensed_version"];
    $nestedData[] = date("d/m/Y",strtotime($row["issued_date"]));
    $nestedData[] = date("d/m/Y",strtotime($row["support_expiry_date"]));
    $nestedData[] = date("d/m/Y",strtotime($row["updates_expiry_date"]));
    $nestedData[] = $row["advanced_clients_licensed"];
    $nestedData[] = $row["users_licensed"];
    $nestedData[] = "<a href='detail-license.php?id=".$row['id_license']."'><button class='btn btn-success'><i class='fa fa-list'></i> Detalhes</button></a>";

}


$json_data = array(
    "draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
    "recordsTotal"    => intval( $totalData ),  // total number of records
    "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
    "data"            => $nestedData   // total data array
);

//echo json_encode($json_data);  // send data as json format

Agora de um print_r() nesta var $json_data

echo "<pre>";
print_r($json_data);
echo "</pre>";

E veja o que retorna

Compartilhar este post


Link para o post
Compartilhar em outros sites


<pre>Array

(

[draw] => 1

[recordsTotal] => 11

[recordsFiltered] => 11

[data] => Array

(

[0] => Array

(

[0] => Isabel e Luan Adega Ltda

[1] => Maria Diretora

[2] => Financeiro

[3] => (31) 2535-4682

[4] => (31) 99129-3741

[5] => thadeu@movewayit.com.br

[6] => 6

)

[1] => Array

(

[0] => Isabel e Luan Adega Ltda

[1] => Jo�o

[2] => Financeiro

[3] => 0

[4] =>

[5] => 0

[6] => 22

)

[2] => Array

(

[0] => Isabel e Luan Adega Ltda

[1] => Felipe

[2] => Diretor

[3] => (31) 2535-4682

[4] => (31) 99129-3741

[5] => thadeu@movewayit.com.br

[6] => 4

)

[3] => Array

(

[0] => Isabel e Luan Adega Ltda

[1] => Financeiro

[2] => Sandro

[3] => (31) 2535-4682

[4] => (31) 99129-3741

[5] => thadeu@movewayit.com.br

[6] => 16

)

[4] => Array

(

[0] => Isabel e Luan Adega Ltda

[1] => Maria Diretora

[2] => Financeiro

[3] => (31) 2535-4682

[4] => (31) 99129-3741

[5] => thadeu@movewayit.com.br

[6] => 7

)

[5] => Array

(

[0] => Isabel e Luan Adega Ltda

[1] => Maria Fernanda

[2] => Diretora

[3] => (31) 2535-4682

[4] => (31) 99129-3741

[5] => thadeu@movewayit.com.br

[6] => 5

)

[6] => Array

(

[0] => Isabel e Luan Adega Ltda

[1] => João

[2] => Diretor

[3] => (31) 2535-4682

[4] => (31) 99129-3741

[5] => thadeu@movewayit.com.br

[6] => 17

)

[7] => Array

(

[0] => Isabel e Luan Adega Ltda

[1] => João Figueiredo

[2] => Diretor

[3] => (31) 2535-4682

[4] => (31) 99129-3741

[5] => thadeu@movewayit.com.br

[6] => 3

)

[8] => Array

(

[0] => Isabel e Luan Adega Ltda

[1] => Financeiro

[2] => Sandro

[3] => (31) 2535-4682

[4] => (31) 99129-3741

[5] => thadeu@movewayit.com.br

[6] => 15

)

[9] => Array

(

[0] => Stefany e Clara Restaurante Ltda

[1] => Stefany

[2] => Financeiro

[3] => (31) 2535-4682

[4] => (31) 99129-3741

[5] => thadeu@movewayit.com.br

[6] => 1

)

)

)

</pre>

​Me retornou os dados direitinhos

Compartilhar este post


Link para o post
Compartilhar em outros sites

blz, Já sabe então, da próxima aguarde, senão as pessoas acham que já tem alguém iterando no seu tópico e nem chega a olhar.

Para usar

header('Content-Type: application/json');
echo json_encode($json_data);
exit();

Compartilhar este post


Link para o post
Compartilhar em outros sites


<?php

/* Database connection start */

$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

/* Database connection end */

// storing request (ie, get/post) global array to a variable

$requestData= $_REQUEST;

$columns = array(

// datatable column index => database column name

0 =>'razao_social',

1 =>'nome',

2 => 'cargo',

3 => 'tel_comercial1',

4 => 'tel_celular1',

5 => 'email1',

6 => 'id_resp',

);

// getting total number records without any search

$sql = "SELECT razao_social,nome, cargo,tel_comercial1, tel_celular1,email1,id_resp ";

$sql.=" FROM responsibles_view";

$query=mysqli_query($conn, $sql) or die("Erro:".mysqli_error($conn));

$totalData = mysqli_num_rows($query);

$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.

$sql = "SELECT razao_social,nome, cargo,tel_comercial1, tel_celular1,email1,id_resp ";

$sql.=" FROM responsibles_view WHERE 1 = 1";

$query=mysqli_query($conn, $sql) or die("Erro:".mysqli_error($conn));

$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.

$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; // adding length

$query=mysqli_query($conn, $sql) or die("Erro:".mysqli_error($conn));

$data = array();

while( $row=mysqli_fetch_array($query) ) { // preparing an array

$nestedData=array();

$nestedData[] = $row["razao_social"];

$nestedData[] = $row["nome"];

$nestedData[] = $row["cargo"];

$nestedData[] = $row["tel_comercial1"];

$nestedData[] = $row["tel_celular1"];

$nestedData[] = $row["email1"];

$nestedData[] = $row["id_resp"];

$data[] = $nestedData;

}

$json_data = array(

"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.

"recordsTotal" => intval( $totalData ), // total number of records

"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData

"data" => $data // total data array

);

header('Content-Type: application/json');

echo json_encode($json_data);

exit();

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sim.. o seu apresentou:

<pre>Array
(
    [draw] => 1
    [recordsTotal] => 11
    [recordsFiltered] => 11
    [data] => Array
        (
            [0] => Isabel e Luan Adega Ltda
            [1] => Maria Diretora
            [2] => Financeiro
            [3] => (31) 2535-4682
            [4] => (31) 99129-3741
            [5] => thadeu@movewayit.com.br
            [6] => 6
            [7] => Isabel e Luan Adega Ltda
            [8] => Jo�o
            [9] => Financeiro
            [10] => 0
            [11] => 
            [12] => 0
            [13] => 22
            [14] => Isabel e Luan Adega Ltda
            [15] => Felipe
            [16] => Diretor
            [17] => (31) 2535-4682
            [18] => (31) 99129-3741
            [19] => thadeu@movewayit.com.br
            [20] => 4
            [21] => Isabel e Luan Adega Ltda
            [22] => Financeiro
            [23] => Sandro
            [24] => (31) 2535-4682
            [25] => (31) 99129-3741
            [26] => thadeu@movewayit.com.br
            [27] => 16
            [28] => Isabel e Luan Adega Ltda
            [29] => Maria Diretora
            [30] => Financeiro
            [31] => (31) 2535-4682
            [32] => (31) 99129-3741
            [33] => thadeu@movewayit.com.br
            [34] => 7
            [35] => Isabel e Luan Adega Ltda
            [36] => Maria Fernanda
            [37] => Diretora
            [38] => (31) 2535-4682
            [39] => (31) 99129-3741
            [40] => thadeu@movewayit.com.br
            [41] => 5
            [42] => Isabel e Luan Adega Ltda
            [43] => João
            [44] => Diretor
            [45] => (31) 2535-4682
            [46] => (31) 99129-3741
            [47] => thadeu@movewayit.com.br
            [48] => 17
            [49] => Isabel e Luan Adega Ltda
            [50] => João Figueiredo
            [51] => Diretor
            [52] => (31) 2535-4682
            [53] => (31) 99129-3741
            [54] => thadeu@movewayit.com.br
            [55] => 3
            [56] => Isabel e Luan Adega Ltda
            [57] => Financeiro
            [58] => Sandro
            [59] => (31) 2535-4682
            [60] => (31) 99129-3741
            [61] => thadeu@movewayit.com.br
            [62] => 15
            [63] => Stefany e Clara Restaurante Ltda
            [64] => Stefany
            [65] => Financeiro
            [66] => (31) 2535-4682
            [67] => (31) 99129-3741
            [68] => thadeu@movewayit.com.br
            [69] => 1
        )


)
</pre>

Compartilhar este post


Link para o post
Compartilhar em outros sites

É o seu esta correto, cara aconselho abrir um outro tópico da área de JS, com o PHP não tem erro, tem que saber como você esta lendo este Json agora.

Faça um debug no JS

Compartilhar este post


Link para o post
Compartilhar em outros sites

Como eu sou uma pessoa de bem B) vou remover os dados sigilosos que você expôs ao invés de "destruir" sua base de dados.

Fica a dica. :ph34r:

Compartilhar este post


Link para o post
Compartilhar em outros sites

Agora o estranho, que eu colocando outro código php, de outra classe que eu já fiz, ele apresenta normalmente os campos, mas adaptando ele pra sql que eu preciso, não roda.

Esse no caso

<?php
/* Database connection start */


$servername = "";
$username = "";
$password = "";
$dbname = "";

$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

/* Database connection end */


// storing request (ie, get/post) global array to a variable
$requestData= $_REQUEST;


$columns = array(
// datatable column index => database column name
0 =>'razao_social',
1 =>'organization_name',
2 => 'organization_type',
3 => 'edition',
4 => 'licensed_version',
5 => 'issued_date',
6 => 'updates_expiry_date',
7 => 'support_expiry_date',
8 => 'advanced_clients_licensed',
9 => 'users_licensed',
10 => 'id_license'
);




// getting total number records without any search
$sql = "SELECT razao_social,organization_name, organization_type,edition, licensed_version,issued_date,updates_expiry_date,support_expiry_date,advanced_clients_licensed,users_licensed,id_license ";
$sql.=" FROM license_view";
$query=mysqli_query($conn, $sql) or die("Erro");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.




$sql = "SELECT razao_social,organization_name, organization_type,edition, licensed_version,issued_date,updates_expiry_date,support_expiry_date,advanced_clients_licensed,users_licensed,id_license ";
$sql.=" FROM license_view WHERE 1 = 1";


if( !empty($requestData['columns'][0]['search']['value']) || !empty($requestData['columns'][1]['search']['value'])) { //age
if ($requestData['columns'][1]['search']['value'] < 1000) {
$sql .= " AND users_licensed BETWEEN " . $requestData['columns'][0]['search']['value'] . " AND " . $requestData['columns'][1]['search']['value'];
}
else{
$sql.=" AND ( users_licensed < '".$requestData['columns'][0]['search']['value'] ."' OR users_licensed > '". $requestData['columns'][1]['search']['value']."' ) ";
}
}
if(!empty($requestData['columns'][2]['search']['value'])){
$sql.=" AND licensed_version LIKE '".$requestData['columns'][2]['search']['value']."%' ";
}
if(!empty($requestData['columns'][3]['search']['value']) && (!empty($requestData['columns'][4]['search']['value']))){
$sql.=" AND organization_type LIKE '".$requestData['columns'][3]['search']['value']."%' OR organization_type LIKE '".$requestData['columns'][4]['search']['value']."%'" ;
}
else if(!empty($requestData['columns'][3]['search']['value']) && (!empty($requestData['columns'][5]['search']['value']))){
$sql.=" AND organization_type LIKE '".$requestData['columns'][3]['search']['value']."%' OR organization_type LIKE '".$requestData['columns'][5]['search']['value']."%'" ;
}
else if(!empty($requestData['columns'][4]['search']['value']) && !empty($requestData['columns'][5]['search']['value'])){
$sql.=" AND organization_type LIKE '".$requestData['columns'][4]['search']['value']."%' OR organization_type LIKE '".$requestData['columns'][5]['search']['value']."%'" ;
}
else if(!empty($requestData['columns'][3]['search']['value']) && !empty($requestData['columns'][4]['search']['value']) && !empty($requestData['columns'][5]['search']['value'])){
$sql.=" AND organization_type LIKE '".$requestData['columns'][3]['search']['value']."%' OR organization_type LIKE '".$requestData['columns'][4]['search']['value']."%' OR organization_type LIKE '".$requestData['columns'][5]['search']['value']."%'" ;
}
else if(!empty($requestData['columns'][3]['search']['value'])){
$sql.=" AND organization_type LIKE '".$requestData['columns'][3]['search']['value']."%'" ;
}
else if(!empty($requestData['columns'][4]['search']['value']) ){
$sql.=" AND organization_type LIKE '".$requestData['columns'][4]['search']['value']."%'";
}
else if(!empty($requestData['columns'][5]['search']['value'])){
$sql.=" AND organization_type LIKE '".$requestData['columns'][5]['search']['value']."%'";
}

if(!empty($requestData['columns'][6]['search']['value']) && empty($requestData['columns'][7]['search']['value'])) {
$sql .= " AND edition LIKE '" . $requestData['columns'][6]['search']['value'] . "%' ";
}

else if(!empty($requestData['columns'][7]['search']['value']) && empty($requestData['columns'][6]['search']['value'])) {
$sql .= " AND edition LIKE '" . $requestData['columns'][7]['search']['value'] . "%' ";
}
else if(!empty($requestData['columns'][6]['search']['value']) && !empty($requestData['columns'][7]['search']['value'])) {
$sql .= " AND edition LIKE '" . $requestData['columns'][6]['search']['value'] . "%' OR edition LIKE '" . $requestData['columns'][6]['search']['value']."%'";
}


if(!empty($requestData['columns'][8]['search']['value']) && !empty($requestData['columns'][11]['search']['value']) && !empty($requestData['columns'][12]['search']['value'])){
$sql .= " AND issued_date BETWEEN '".$requestData['columns'][11]['search']['value']."' AND '".$requestData['columns'][12]['search']['value']."'";
}



if(!empty($requestData['columns'][13]['search']['value']) || !empty($requestData['columns'][14]['search']['value'])){
$value = $requestData['columns'][13]['search']['value'];
if($value === 'n'){
$sql.="AND advanced_clients_licensed > 1";
}
else{
$sql.="AND advanced_clients_licensed < 1";
}
}

if(!empty($requestData['search']['value'])){
$sql.=" AND razao_social LIKE '%".$requestData['search']['value']."%'".
"OR organization_name LIKE '%".$requestData['search']['value']."%'".
"OR organization_type LIKE '%".$requestData['search']['value']."%'".
"OR edition LIKE '%".$requestData['search']['value']."%'".
"OR licensed_version LIKE '%".$requestData['search']['value']."%'".
"OR issued_date LIKE '%".$requestData['search']['value']."%'".
"OR updates_expiry_date LIKE '%".$requestData['search']['value']."%'".
"OR support_expiry_date LIKE '%".$requestData['search']['value']."%'".
"OR advanced_clients_licensed LIKE '%".$requestData['search']['value']."%'".
"OR users_licensed LIKE '%".$requestData['search']['value']."%'".
"OR id_license LIKE '%".$requestData['search']['value']."%'";
}
if(!empty($requestData['columns'][15]['search']['value'])){
$sql.=" AND razao_social LIKE '".$requestData['columns'][15]['search']['value']."%' ";
}
$query=mysqli_query($conn, $sql) or die("Erro:".mysqli_error($query));

$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.

$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; // adding length

$query=mysqli_query($conn, $sql) or die("Erro:".mysqli_error($query));




$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();

$nestedData[] = $row["razao_social"];
$nestedData[] = $row["organization_name"];
$nestedData[] = $row["organization_type"];
$nestedData[] = $row["edition"];
$nestedData[] = $row["licensed_version"];
$nestedData[] = date("d/m/Y",strtotime($row["issued_date"]));
$nestedData[] = date("d/m/Y",strtotime($row["support_expiry_date"]));
$nestedData[] = date("d/m/Y",strtotime($row["updates_expiry_date"]));
$nestedData[] = $row["advanced_clients_licensed"];
$nestedData[] = $row["users_licensed"];
$nestedData[] = "<a href='detail-license.php?id=".$row['id_license']."'><button class='btn btn-success'><i class='fa fa-list'></i> Detalhes</button></a>";

$data[] = $nestedData;
}



$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);

echo json_encode($json_data); // send data as json format

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.