Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db = mysqli_connect("localhost", "tvstar5_gocyw", "123123123", "tvstar5_gocyw");
- if(isset($_POST['downloads'])) {
- //create query to select as data from your table
- $select = "SELECT * FROM cyw_netsignups";
- //run mysql query and then count number of fields
- $export = mysqli_query ( $db, $select )
- or die ( "Sql error : " . mysql_error( ) );
- $fields = mysqli_num_fields ( $export );
- //create csv header row, to contain table headers
- //with database field names
- for ( $i = 0; $i < $fields; $i++ ) {
- /* line 481 */ $header .= mysqli_fetch_field( $export ) . ",";
- }
- //this is where most of the work is done.
- //Loop through the query results, and create
- //a row for each
- while( $row = mysqli_fetch_row( $export ) ) {
- $line = '';
- //for each filepro_fieldcount(oid)d in the row
- foreach( $row as $value ) {
- //if null, create blank field
- if ( ( !isset( $value ) ) || ( $value == "" ) ){
- $value = ",";
- }
- //else, assign field value to our data
- else {
- $value = str_replace( '"' , '""' , $value );
- $value = '"' . $value . '"' . ",";
- }
- //add this field value to our row
- $line .= $value;
- }
- //trim whitespace from each row
- $data .= trim( $line ) . "\n";
- }
- //remove all carriage returns from the data
- $data = str_replace( "\r" , "" , $data );
- //create a file and send to browser for user to download
- header("Content-type: application/vnd.ms-excel");
- header("Content-disposition: csv" . date("Y-m-d") . ".csv");
- header( "Content-disposition: filename=".$file_name.".csv");
- print "$header\n$data";
- exit;
- }
- ?>
- <form action="" method="post">
- <input type="submit" name="downloads" value="Download">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement