1

PHPを介してodbc接続でデータベースにクエリを実行しています。データベースにクエリを実行すると、最初の行が2回返され、残りの行が正しい回数返されます。

クエリの例:

$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;
          }
4

2 に答える 2

1

You have checked the query result is good outside of this app -- good for you. That means the problem is your loop structure, or maybe your method of getting the data such as odbc_fetch_array().

I ran into this problem once, and I can't recall the solution. I had to try alternative methods to isolate the cause.

For example, instead of for (), try foreach ($elems as $elem) { ... }.

Of course, simplify all the other aspects while you are trouble-shooting. For example, remove the if() structure.

于 2013-07-05T17:37:53.157 に答える