A note for those of you using my osTicket Reports MOD: This is not what I’m using for that.
A note for those of you using my osTicket Reports MOD: This is not what I’m using for that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <?php $host = 'localhost' ; $user = 'userName' ; $pass = 'password' ; $db = 'databaseName' ; $table = 'tableName' ; $file = 'export' ; $link = mysql_connect( $host , $user , $pass ) or die ( "Can not connect." . mysql_error()); mysql_select_db( $db ) or die ( "Can not connect." ); $result = mysql_query( "SHOW COLUMNS FROM " . $table . "" ); if (mysql_num_rows( $result ) > 0) { while ( $row = mysql_fetch_assoc( $result )) { $csv_output .= $row [ 'Field' ]. ", " ; $i ++; } } $csv_output .= "\n" ; $values = mysql_query( "SELECT * FROM " . $table . "" ); while ( $rowr = mysql_fetch_row( $values )) { for ( $j =0; $j < $i ; $j ++) { $csv_output .= $rowr [ $j ]. ", " ; } $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 ; ?> |