Thursday, April 22, 2010

Result Set to Array

$sql="SELECT column_a FROM table";
$rs=odbc_exec($conn,$sql);

$arr = array(); //you need this in case it's empty, otherwise the foreach will throw an error

while( $col = odbc_fetch_array($rs) ) {
array_push($arr, $col);
}

foreach ($arr as $value) {
$sql2="SELECT * FROM table WHERE column_b = " . $value["column_a"];
$rs2=odbc_exec($conn,$sql2);
}

No comments: