I need to return two queries.
$id = $_POST['id'];
$id = end(explode('editarnovoservico', $id));
$searchid = $pdo->query('SELECT * FROM cad_servicos WHERE id = '.$id);
$searchid = $searchid->fetchAll(PDO::FETCH_ASSOC);
$searchtiposervico = $pdo->query('SELECT * FROM tipo_servicos');
$searchtiposervico = $searchtiposervico->fetchAll(PDO::FETCH_ASSOC);
$array['searchid'] = $searchid;
$array['searchtiposervico'] = $searchtiposervico;
foreach ($array['searchtiposervico'] as $key => $value) {
$array['searchtiposervico'][$key]['id'] = $value['id'];
$array['searchtiposervico'][$key]['tipo_servico'] = utf8_encode($value['tipo_servico']);
}
$array['searchid'] = $searchid;
var_dump($array);
$array2['searchtiposervico'] = $searchtiposervico;
var_dump($array2);
The first one returns:
array(1) {
["searchid"]=>
array(1) {
[0]=>
array(5) {
["id"]=>
string(3) "402"
["nome"]=>
string(7) "bla bla"
["cobrado"]=>
string(1) "1"
["id_tipo_servico"]=>
string(1) "1"
["novo"]=>
string(1) "1"
}
}
}
And the second:
array(2) {
["searchtiposervico"]=>
array(8) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["tipo_servico"]=>
string(12) "Desconhecido"
}
[1]=>
array(2) {
["id"]=>
string(1) "2"
["tipo_servico"]=>
string(8) "Liga��es"
}
[2]=>
array(2) {
["id"]=>
string(1) "3"
["tipo_servico"]=>
string(3) "Sms"
}
[3]=>
array(2) {
["id"]=>
string(1) "4"
["tipo_servico"]=>
string(9) "Descontos"
}
[4]=>
array(2) {
["id"]=>
string(1) "5"
["tipo_servico"]=>
string(6) "Multas"
}
[5]=>
array(2) {
["id"]=>
string(1) "6"
["tipo_servico"]=>
string(8) "Parcelas"
}
[6]=>
array(2) {
["id"]=>
string(1) "7"
["tipo_servico"]=>
string(8) "Internet"
}
[7]=>
array(2) {
["id"]=>
string(1) "8"
["tipo_servico"]=>
string(11) "Assinaturas"
}
}
}
How would I return both in JSON
? I tried to join the two array
and then it gives json_encode()
, but it did not work.
~ edit : After doing a foreach
traversing the data with utf8_encode()
, cosegui ... but there is gabiarra. hhaha =)
$array['searchid'] = $searchid;
$array['searchtiposervico'] = $searchtiposervico;
foreach ($array['searchtiposervico'] as $key => $value) {
$array['searchtiposervico'][$key]['id'] = $value['id'];
$array['searchtiposervico'][$key]['tipo_servico'] = utf8_encode($value['tipo_servico']);
}
echo json_encode($array, true);