I am not sure what you are trying to do , but it seems like you want to take the last columns value and use it for finding a value from another table and add that to the record. For that i think something like this should work:
$link = mysql_connect($host, $user, $pass) or die("Can not connect to the host." . mysql_error());
mysql_select_db($db) or die("Can not connect to the particular database.");
$csv_output = "";
$last_col = "";
$values = mysql_query("SELECT * FROM ".$table." WHERE forwarded_oce='1'");
while ($rowr = mysql_fetch_assoc($values)) {
if(!$csv_output){
foreach($rowr as $fld_name => $fld_val){
$csv_output .= $fld_name.", ";
$last_col = $fld_name;
}
$csv_output .= "New_Field\n";
}
$smallerid = $rowr[$last_col];
list($smaller) = mysql_fetch_row(mysql_query("SELECT budget FROM `db`.`table` WHERE id = '$smallerid'"));
$rowr[] = $smaller;
$csv_output .= implode(', ' , $rowr) ;
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;