odbc_fetch_row fails when result empty

admin

Administrator
Staff member
Hi there, I am doing

$sqlstatement = "SELECT CODIV FROM $db_table where SUPLAST LIKE '$prof_lastname' AND PASSWRD LIKE '$Sup_Log_Pass'";
$sth = odbc_exec($dbh,$sqlstatement);
while(odbc_fetch_row($sth)){blahblah}

I know through testing that my while statement is functioning as long as $sth has a value. But if I do the Select and the program does not find a matching record in my database, (so $sth would be empty) the odbc_fetch_row() is simply not executing. I put an echo line in my while statement to test to see if I entered the loop. If it found a record, it does. But if there was no matching record, it doesn't run. How do test for this so I can redirect the user? is there a way to test $sth before I do the while loop to see if it is empty? (NO, if(!$sth) does not work nor does if($sth == "false") ) If you echo $sth when you know it's empty it says this is the value: "Resource #2" go figure?
Thanks in advance for your help,
Tinny
 
Back
Top