<html>
<head>
<title>Consulta</title>
</head>
<body>
<?php
$txtArquivo = "COMPRAS.DBF";
$txtCampo = "PRODUTO";
$txtPesquisa = ($_POST["filtro3"]);
$dsn = "DRIVER={Microsoft dBase Driver (*.dbf)};DBQ=".dirname($_SERVER['SCRIPT_FILENAME'])."/meusarq/agenda/;";
$conn= odbc_connect($dsn,"","");
if(!$conn)
{ exit("conexao falhou: ".odbc_errormsg()); }
if (ctype_digit($txtPesquisa)) {
$sql="SELECT * FROM ".$txtArquivo." WHERE ".$txtCampo." = '".$txtPesquisa."'";
} else {
$sql="SELECT * FROM ".$txtArquivo." WHERE ".$txtCampo." LIKE '%".$txtPesquisa."%'";
}
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
$i = 0;
$fieldCount = odbc_num_fields($rs);
echo '<table Border="1"><tr>';
while ($i < $fieldCount)
{
$i++;
$fieldName = odbc_field_name($rs, $i);
echo "<th>$fieldName</th>";
}
echo "</tr>";
while (odbc_fetch_row($rs))
{
echo "<tr>";
$i = 0;
while ($i < $fieldCount)
{
$i++;
$fieldName = odbc_field_name($rs, $i);
$compname=odbc_result($rs,$fieldName);
if ($i=1){
echo "<td><a href='dproduto.php' target='_top'>".$compname."</a></td>";
}else{
echo "<td>$compname</td>";
}
}
echo "</tr>";
}
echo "</table>";
odbc_close($conn);
?>
</body>
</html>
O problema, creio eu, deve estar no if da linha 43, pois, aparentemente, ele está em loop aÃ.
Veja como fica a tela dessa consulta:
Se eu tiro o if e o else, funciona perfeitamente, tanto deixando apenas:
{echo "<td><a href='dproduto.php' target='_top'>".$compname."</a></td>";}
Quanto deixando apenas:
{echo "<td>$compname</td>";}
Pelo que vi no manual de PHP, a sintaxe da função está correta.
O que estou fazendo errado?