While - Returns a record

Asked

Viewed 79 times

0

I have a Webservice that returns me some data like, statement, balance etc...

But when I have the extract displayed, it returns only the first record, not all. And always repeats the first record.

<?php
session_start();
$cartao = $_SESSION['cartao'];
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />    
<?php

require_once 'vale-consulta.php';

try {

    $dados = array(
        'cd_grupo'        => '38',
        'de_login_usu'    => 'loginusuario',
        'de_senha_usu'    => 'senhapassword',
        'nu_cartao'       => $cartao,
        'fl_apenas_saldo' => 'N'
    );

    $vale = new ValeConsulta();
    $resposta = $vale->consultar( $dados );

    if ( $vale->tem_erro() ) {
        echo "Código: " . $resposta->erro->cod . "<br >\n";
        echo "MSG: " . $resposta->erro->msg . "<br >\n";
    } else {

        $nick         = $resposta->nome;
        $nome       = explode(" ", $nick);
        $saldo         = $resposta->vl_saldo;
        $ldata         = $resposta->lancamentos->lancto->dt_lancto;
        $ldesc      = $resposta->lancamentos->lancto->descricao;
        $lvalor       = $resposta->lancamentos->lancto->valor;
        $extrato    = $ldesc."</br>".$ldata."</br>".$lvalor."</br>";
    }

} catch( SoapFault $fault ) {
    echo "Erro: " . $fault->faultcode . " - " . $fault->faultstring;
}
?>

While

<?php
include("mostra.php")
//mostra extrato

$i = 1;
    while($i < 5) {
            echo $extrato; 
            $++;
        }
?>

Returning me

Lucas SOBRE NOME MEU //MEU NOME COMPLETO
124                  //SALDO
KIDELICIA            //EXTRATO NOME DA EMPRESA
07/09/2016           //DATA EXTRATO
10,50 D              //VALOR NO DEBIDO

PDF HERE

  • Put in a more meaningful snippet of code. As $extract is being shown it will always have the same value, only the index that is being incremented.

  • @gmsantos , I’m new in PHP friend not yet know all functions! how can I do this?

  • 1

    Lucas, I don’t know how I can help you, try [Dit] your question and make it clearer what your question is. Read again: [tour] and [mcve]

  • You need to put all the necessary code so that it is possible to do a minimum of analysis of the problem, anyway, already I say that if you are using a webservice, you probably do not know the amount of records that it will return, so you should not use the WHILE command (at least not with fixed value) but use a FOREACH, which better meets this need.

  • @Kennyrafael gave an edited, where I find Ocs of this FOREACH ? to do this!

  • Put the result of the method $vale->consultar( $dados ); because it should return an array with the results, then you will make a for in the variable $resposta and so list everything.

  • @Neuberoliveira follows the edition, which returns me and the PDF of the webservice

  • @Lucasbicalleto can use the PHP manual, online, http://php.net/manual/en/control-structures.foreach.php

  • @stderr well observed, it was just a typo. because it was simulating what I am doing!

  • @Lucasbicalleto can complement the answer with what is written on the screen when you execute this echo var_dump($reply);

  • puts this below the $answer = $voucher->query( $data );

  • @Hiagosouza worked, now as I see it ordered because it looks like this : http://pt-br.tinypic.com/r/ifbqfs/9

  • puts this echo '<pre>';print_r($reply);echo '</pre>'; please for me to see the structure in place of echo var_dump...

  • then forward the print.

  • @HiagoSouza http://pt-br.tinypic.com/r/9q9or6/9

Show 10 more comments

1 answer

0


You are recovering an XML try to go through the array as below.

$resposta = $vale->consultar( $dados );
foreach($resposta->lancamentos->lancto as $info) {

    echo $info->dt_lancto . " - " . $info->descricao . " - " . info->valor;

}
  • Perfect, many thanks @Hiago Souza and to all who will contribute!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.