I dont know if this thing is a php problem or a firebird problem.. i never saw something so weird in my life... the problem is the folowing:
I have a query, this one:
SELECT CLIENTES.*, CIDADES.CID_NOME, CIDADES.CID_ESTADO
FROM CLIENTES
JOIN CIDADES ON (CLIENTES.CID_COD=CIDADES.CID_COD)
It works fine, but the problem is in the results, it takes a value, and keeps printing the SAME value in all the rest of the results, but the weird stuff.. is that it prints one line, skips one and print the value again like this:
ID, NAME, COMENT:
01, name1, repeated value
02, name2, skip this
03, name3, repeated value
04, name5, skip this
05, name6, repeated value
06, name7, skip this
07, name8, repeated value
08, name9, skip this
The ID and NAME are correts, and the other two values keep repeating, here are my REAL results, its kinda messy ok?
1312312313212312
3463622213212312Venda suspensa !!!
3406303013212312Venda suspensa !!!
81451340
3462253613212312Venda suspensa !!!
3406848881451340
3462253691410033Venda suspensa !!!
3406848881451340
3462253691410033Venda suspensa !!!
3406848881451340
This value continues to repeat till the end of the results, but the other fields are all correct, but those two keep freaking repeating.
Anyone already saw something like it somewhere? I dont have ANY ideas what could be the problem, i ve checked EVERYTHING and theres nothing wrong with my code, the same code with another table return correct values, i dont know what to do 🙁
My php code is the following:
this is the function to execute the query and return me the values:
function consulta($id, $sql){
if($sql != '') {
$resultado = ibase_query($id, $sql) or die(ibase_errmsg());
while($item = ibase_fetch_assoc($resultado)){
$items[] = $item;
}
$rows = count($items);
if($rows > 0) {
ibase_free_result($resultado);
return $items;
} else {
return false;
}
} else {
return false;
}
}
And this is the function to show the data:
$clientes = consulta($conexao_id, $sql);
if($clientes) {
if($arquivo = fopen("txt/cad_cli.txt", "w+")) {
echo "Arquivo aberto!<br />";
foreach($clientes as $cliente) {
fwrite($arquivo, sprintf("%012s", $cliente['CLI_COD']));
fwrite($arquivo, sprintf("%-50s", $cliente['CLI_NOME']));
fwrite($arquivo, sprintf("%-40s", $cliente['CLI_ENDERECO']));
fwrite($arquivo, sprintf("%-35s", $cliente['CLI_BAIRRO']));
fwrite($arquivo, sprintf("%-8s", $cliente['CLI_CEP']));
fwrite($arquivo, sprintf("%-30s", $cliente['CID_NOME']));
fwrite($arquivo, sprintf("%-2s", $cliente['CID_ESTADO']));
fwrite($arquivo, sprintf("%012s", $cliente['CLI_LIM_CREDITO']));
fwrite($arquivo, sprintf("%-16s", $cliente['CLI_CNPJ_CPF']));
fwrite($arquivo, sprintf("%-18s", $cliente['CLI_IE_RG']));
fwrite($arquivo, sprintf("%-2s", $cliente['CLI_DDD']));
fwrite($arquivo, sprintf("%-8s", $cliente['CLI_TELEFONE']));
fwrite($arquivo, sprintf("%-8s", $cliente['CLI_CELULAR']));
fwrite($arquivo, sprintf("%-50s", $cliente['CLI_OBS']));
fwrite($arquivo, "\r\n");
echo "cliente: " . $cliente['CLI_NOME'] . ", gravado!<br />";
}
}
} else {
echo "Clientes não encontrados!";
}
Any help and ideas are welcome.
Thanx in advance,
Fábio.