Date: 03/16/07 (MySQL Communtiy) Keywords: mysql, rss, browser, sql [edit] - solved in comments $rsSearchResults = mysql_query($sql) or die(mysql_error()); $out = ''; $fields = mysql_list_fields('dataprod_a5data_com','canman'); $columns = mysql_num_fields($fields); // Put the name of all fields for ($i = 0; $i < $columns; $i++) { $l=mysql_field_name($fields, $i); $out .= '"'.$l.'",'; } $out .="\n"; // Add all values in the table while ($l = mysql_fetch_array($rsSearchResults)) { for ($i = 0; $i < $columns; $i++) { $out .='"'.$l["$i"].'",'; } $out .="\n"; } // Output to browser with appropriate mime type, you choose ;) //header("Content-type: text/x-csv"); //header("Content-type: text/csv"); header("Content-type: application/csv"); header("Content-Disposition: attachment; filename=search_results.csv"); echo $out; $currentdownloads++; $q2 = mysql_query("UPDATE canman_users SET CurrentDownloads = '".$currentdownloads."' WHERE Username = '".$un."'"); exit; What I am wanting to do is not have all of the columns in the downloaded file. I have tried only including the columns I want in the select statement but all the data ends up being moved over by however many columns are missing - for example, the BusinessName column data ends up under the ID column heading. Is there anyway that I can exclude the certain columns when it's pulling out the column names and adding them to $out? Thanks!
|