sacjamm 0 Denunciar post Postado Dezembro 9, 2016 Olá pessoal, Estou com um problema, ao gerar um XML. Eu tenho uma tabela pedidos, a tabela produtos e a tabela clientes. Eu preciso gerar um XML somente de clientes com status ativo, porém cada cliente tem um pedido, então no XML eu tenho que setar os produtos de cada cliente, isso também por data. Ex.: Vou digitar no campo de data uma data, pra filtrar todos os clientes que fez pedidos nesta data que pesquisei. deverá retornar vários resultados. Mais primeiro o sistema deve selecionar todos os dados do pedido através da data, depois terá que selecionar todos os usuários e produtos de cada linha que a seleção do pedido retornou. Eu consigo fazer tudo isso. Mais acontece que eu não tenho sucesso ao gerar o XML, o arquivo XML só me retorna as tags mais sem valor. Por favor, segue o código: $situacao = filter_input(INPUT_GET, 'situacao', FILTER_DEFAULT); $data = filter_input(INPUT_GET, 'data', FILTER_DEFAULT); $sts = 'ativo'; $sql = new Read; $sql->ExeRead("ws_pedidos", "WHERE data_pedido = :data AND status_pedido = 3 GROUP BY cliente_id ORDER BY data_pedido ASC", "data={$data}"); //header('Content-Disposition: attachment; filename="xml-all-' . $data . '.xml"'); # Instanciando o XMLWriter $xml = new XMLWriter; $xml->openMemory(); # Definindo o encoding do XML $xml->startDocument('1.0', 'utf-8'); if ($sql->getResult()): while ($resPedido = $sql->getResult()): $sql->ExeRead("uni_usuario", "WHERE id = :uid AND situacao = :sts", "uid={$resPedido->cliente_id}&sts={$sts}"); if ($sql->getResult()): $cliente = $sql->getResult()[0]; endif; echo '<pre>'; var_dump($resPedido); echo '</pre>'; $sql->ExeRead("ws_posts", "WHERE post_id = :pid", "pid={$resPedido->produto_id}"); if ($sql->getResult()): $produto = $sql->getResult()[0]; endif; # Primeiro elemento do XML $xml->startElement("pedido_emissao_nfe"); # Query na tabela albuns # Criando elemento album $xml->startElement("dados_cliente"); $xml->startElement("id_cliente"); $xml->text("{$cliente->id}"); $xml->endElement(); $xml->startElement("nome"); $xml->text("{$cliente->nome} {$cliente->sobrenome}"); $xml->endElement(); $xml->startElement("documento"); $xml->text("$cliente->cpf"); $xml->endElement(); # Setando os atributos //$xml->writeAttribute("nome", "{$album->nome} {$album->sobrenome}"); $xml->startElement("nascimento"); $xml->text("$cliente->nascimento"); $xml->endElement(); $xml->startElement("endereco"); $xml->text("$cliente->endereco"); $xml->endElement(); $xml->startElement("numero"); $xml->text("$cliente->numero"); $xml->endElement(); $xml->startElement("complemento"); $xml->text("$cliente->complemento"); $xml->endElement(); $xml->startElement("cidade"); $xml->text("{$cliente->cidade}"); $xml->endElement(); $xml->startElement("uf"); $xml->text("$cliente->estado"); $xml->endElement(); $xml->startElement("cep"); $xml->text("$cliente->cep"); $xml->endElement(); $xml->startElement("bairro"); $xml->text("$cliente->bairro"); $xml->endElement(); $xml->startElement("telefone"); $xml->text("{$cliente->fone}"); $xml->endElement(); $xml->endElement(); //termina cliente //inicia produto $xml->startElement("produto"); # Setando os atributos $xml->startElement("id_produto"); $xml->text("$produto->post_id"); $xml->endElement(); $xml->startElement("nome_produto"); $xml->text("$produto->post_title"); $xml->endElement(); $xml->startElement("qtde"); $xml->text("$produto->post_frasco"); $xml->endElement(); $xml->startElement("unidade"); $xml->text("Frasco"); $xml->endElement(); $xml->startElement("frete"); $xml->text("$produto->post_frete"); $xml->endElement(); $xml->startElement("conteuto"); $xml->text("$produto->post_content"); $xml->endElement(); $xml->startElement("preco"); $xml->text("$produto->post_price"); $xml->endElement(); $xml->endElement(); # Fechando o elemento album $xml->endElement(); # Fechando o elemento featureset endwhile; endif; $xml->endElement(); # Definindo cabecalho de saida header('Content-type: text/xml'); # Imprimindo a saida do XML print $xml->outputMemory(true); Att, Alisson Maciel Compartilhar este post Link para o post Compartilhar em outros sites
Maykel-ctba 233 Denunciar post Postado Dezembro 9, 2016 Tente tirar as variáveis de dentro das aspas... Errado = "$teste" Certo = $teste Outra coisa, libere a visualização de erros do seu PHP. Coloque isso no começo do seu código: ini_set("display_errors", true); error_reporting(E_ALL); Compartilhar este post Link para o post Compartilhar em outros sites
sacjamm 0 Denunciar post Postado Dezembro 9, 2016 Bom dia, Agora me retornou estes erros, algo bastante interessante é que eu estou fazendo o include do config da estrutura da pasta toda justamente pra nao informar que a pasta está errada e está retornando o erro, o arquivo config está neste caminho correto. Warning: include_once(/home/fit/sys.fit-turbo.com/config/config.php): failed to open stream: No such file or directory in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 4 Warning: include_once(): Failed opening '/home/fit/sys.fit-turbo.com/config/config.php' for inclusion (include_path='.:/opt/ntphp/php54/lib/php') in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 4 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 31 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 36 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 42 NULL Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 54 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 54 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 58 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 58 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 58 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 58 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 62 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 62 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 68 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 68 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 72 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 72 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 76 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 76 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 80 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 80 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 84 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 84 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 88 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 88 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 92 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 92 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 96 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 96 Notice: Undefined variable: cliente in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 100 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 100 Notice: Undefined variable: produto in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 112 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 112 Notice: Undefined variable: produto in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 116 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 116 Notice: Undefined variable: produto in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 120 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 120 Notice: Undefined variable: produto in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 128 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 128 Notice: Undefined variable: produto in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 132 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 132 Notice: Undefined variable: produto in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 136 Notice: Trying to get property of non-object in /home/fit/sys.fit-turbo.com/modulos/xml/xml-all.php on line 136 Frasco Aguardo retorno. Compartilhar este post Link para o post Compartilhar em outros sites