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
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
@gmsantos , I’m new in PHP friend not yet know all functions! how can I do this?
– user50712
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]
– gmsantos
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.
– Kenny Rafael
@Kennyrafael gave an edited, where I find Ocs of this FOREACH ? to do this!
– user50712
Put the result of the method
$vale->consultar( $dados );
because it should return an array with the results, then you will make afor
in the variable$resposta
and so list everything.– Neuber Oliveira
@Neuberoliveira follows the edition, which returns me and the PDF of the webservice
– user50712
@Lucasbicalleto can use the PHP manual, online, http://php.net/manual/en/control-structures.foreach.php
– Jorge B.
@stderr well observed, it was just a typo. because it was simulating what I am doing!
– user50712
@Lucasbicalleto can complement the answer with what is written on the screen when you execute this echo var_dump($reply);
– Hiago Souza
puts this below the $answer = $voucher->query( $data );
– Hiago Souza
@Hiagosouza worked, now as I see it ordered because it looks like this : http://pt-br.tinypic.com/r/ifbqfs/9
– user50712
puts this echo '<pre>';print_r($reply);echo '</pre>'; please for me to see the structure in place of echo var_dump...
– Hiago Souza
then forward the print.
– Hiago Souza
@HiagoSouza http://pt-br.tinypic.com/r/9q9or6/9
– user50712