Description: This script will export the results of a mySQL query to a Comma Separated Value (CSV ) format. Very handy for importing and exporting data.
Language: PHP Highlight Mode: PHP Last Modified: March 16th, 2009
// Export to CSVIF($_GET['action']=='export'){$rsSearchResults=MYSQL_QUERY($sql,$db) or DIE(MYSQL_ERROR());$out='';$fields=MYSQL_LIST_FIELDS('database','table',$db);$columns=MYSQL_NUM_FIELDS($fields);// Put the name of all fieldsFOR($i=0;$i<$columns;$i++){$l=MYSQL_FIELD_NAME($fields,$i);$out.='"'.$l.'",';}$out.="\n";// Add all values in the tableWHILE($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;EXIT;}
SQL University.net courses meet the most demanding needs of the business world for advanced education
in a cost-effective manner. SQL University.net courses are available immediately for IT professionals
and can be taken without disruption of your workplace schedule or processes.
Compared to traditional travel-based training, SQL University.net saves time and valuable corporate
resources, allowing companies to do more with less. That's our mission, and that's what we deliver.