Don't use the same resource/result identifier as the first query (see $r1 and $r2 below).
$r1=odbc_exec($handle,$sql);
...
while(odbc_retch_row($r1)) {
...
$r2=odbc_exec($handle,$newsql);
}
Lars is right though, if you can do it with a join it will be much faster. A join won't always work though...