'odbc query returns the first row twice then returns the rest normally
I am querying a database with an odbc connection through php. When I query the db it returns the first row twice and then the rest of the rows the correct amount of times.
Example query:
$stm = SELECT[sUsername] FROM [dbo].[Abilis].[Users] WHERE sUsername = ?;
$pstm = odbc_prepare($conn, $stm);
$exc = odbc_execute($query, array($Username));
I have also tried using DISTINCT but that has not worked either.
EDIT:
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;
}
Solution 1:[1]
The use of the function odbc_fetch_array ($pstm, $i) with the second parameter starting with zero causes the problem. When you use 0, and the second time 1, it will give you the same result. You could use a while-loop instead of a for-loop and don't use the second parameter.
while ($row = odbc_fetch_array($result))
{
// do something
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ouflak |
