【发布时间】:2013-07-05 12:59:48
【问题描述】:
我正在通过 php 查询具有 odbc 连接的数据库。当我查询数据库时,它会返回第一行两次,然后其余行返回正确的次数。
查询示例:
$stm = SELECT[sUsername] FROM [dbo].[Abilis].[Users] WHERE sUsername = ?;
$pstm = odbc_prepare($conn, $stm);
$exc = odbc_execute($query, array($Username));
我也尝试过使用 DISTINCT,但也没有用。
编辑:
for($i=0; $i<odbc_num_rows($pstm);$i++){
$row = odbc_fetch_array($pstm, $i);
if($row['OnCreditHold'] == '1'){
$out = '<button style="color:red;margin:0 auto;" class="btn" onclick="'.'window.location.href='."'information.php?info=".$row['Account_no'];
$out .= "'".'">'.$row['Name'].'</br>';
$out .= $row['Del_ad1'].'</button>';
}
else{
$out = '<button class="btn" style="margin: 0 auto;" onclick="'.'window.location.href='."'information.php?info=".$row['Account_no'];
$out .= "'".'">'.$row['Name'].'</br>';
$out .= $row['Del_ad1'].'</button>';
}
echo $out;
}
【问题讨论】:
-
确保您没有将该用户名插入两次
-
如果您在 php 应用程序之外运行查询会发生什么?
-
您能否添加一些代码来显示您如何遍历结果集?
-
如果我在应用程序之外运行它,则没有重复。
-
@WhiteSnow - 我有一个模糊的记忆,odbc_ 函数返回的结果集是 1 索引的,而不是你所期望的 0 索引的(我在手册页上找不到任何内容支持这一点,除了在php.net/manual/en/function.odbc-result.php 上的注释)。