Ah, okay. That is because you are creating the file inside of the while, so you make a new file every time through. Try this...
Code:
$sql = "SELECT bkar_inv_sonum
FROM BKARINV
WHERE bkar_inv_orddte BETWEEN('2008-06-01' and '2008-06-30')
AND bkar_inv_loc = 'UNI'
AND bkar_inv_invdte IS NULL";
if(!$rs = odbc_exec($conn, $sql)) {exit(odbc_errormsg());}
$f = fopen("tmp_temp.csv", "w");
while (odbc_fetch_array ($rs))
{
$so = odbc_result($rs,"bkar_inv_sonum")."\n";
fwrite($f, $so);
}
fclose($f);
odbc_close($conn);
Notice that the fopen happens before the while loop. It does not write to the file until you use fclose, so it is building $f as an array.
I don't know what you are trying to find, but using the null or zero date will also pick up canceled orders. To get open orders you'd want to use something like
AND (bkar_invl_pqty <> '0' OR bkar_invl_ubo <> '0')
(instead of the NULL line) to grab open orders with quantities awaiting shipment.
I also fiddled with your SQL to use a BETWEEN instead of the other two cases. Much faster.