+1  A: 

you use

mysql_query

but you do not get the results row like :

mysql_result or mysql_fetch_row

add after the query line another line like:

$smaller = mysql_query("SELECT budget FROM `db`.`table` WHERE id='$smallerid'");

$smaller = mysql_fetch_row($smaller);
Haim Evgi
In this case it works :) not completely but it works. It returns a string - array, so i guess i need to play around with it for a while to return orrect value of the array as well, but thanks for help! you really saved me!!! (hug)
Cninroh
@Cninroh ... give his answer an upvote (left side of answer, up arrow) and if his answer fixed your issue, accept it as the correct answer ( by using the check sign on left, under the up and down arrow)
Sabeen Malik
A: 

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;
Sabeen Malik