I have the following PHP that will return the results in my query to me in CSV format, but the code (two letters) in the LIKE instruction, as shown above, should change between several different codes.
I have about 30 different codes. I need to define all codes, for example:
CV, LC, RCA, JOR, etc.
And let the script create a new CSV for each other code and quickly go through and process each one one by one. So in the end I have 30 files. I may need to do this several times, so manually changing it 30 times is not my top option.
<?php // database variables $hostname = "localhost"; $user = "###"; $password = "###"; $database = "###"; $select = "select * from subscribers where list=27 and custom_fields LIKE '%\%CV\%%'"; $con = mysql_connect($hostname, $user, $password); $db_selected = mysql_select_db($database, $con); // Check connection if (!$con) { die('Could not connect: ' . mysql_error()); } $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) ); $fields = mysql_num_fields ( $export ); for ( $i = 0; $i < $fields; $i++ ) { $header .= mysql_field_name( $export , $i ) . "\t"; } while( $row = mysql_fetch_row( $export ) ) { $line = ''; foreach( $row as $value ) { if ( ( !isset( $value ) ) || ( $value == "" ) ) { $value = "\t"; } else { $value = str_replace( '"' , '""' , $value ); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim( $line ) . "\n"; } $data = str_replace( "\r" , "" , $data ); if ( $data == "" ) { $data = "\n(0) Records Found!\n"; } header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=list-export.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; ?>
source share