Here is my situation. I am sending records to database through php file. Then I have a date field being set with now(). It adds the date in this format: 2013-08-01
Then I am exporting the database to a csv. It all works fine. However, I need to take the dashes out when I am exporting it to the csv. So I need it to read: 20130801
Is there a way to do this? Here is my export to csv code:
$from = $_REQUEST['from'];
$to = $_REQUEST['to'];
$filename = "APGE_ELEC_" . $to;
header('Content-Disposition: attachment; filename="'.$filename.'".csv"');
$hostname = ""; //SET SERVER/HOSTNAME
$dbusername = ""; //SET DATABASE USERNAME
$dbname = ""; //SET DATABASE NAME
$dbpassword = ""; //SET DATABASE USERNAME
$dbhandle = mysql_connect($hostname, $dbusername, $dbpassword)
or die("Unable to connect to MySQL");
$selected = mysql_select_db($dbname,$dbhandle)
or die("Could not select Data Base");
//$query = "SELECT * FROM v88374 WHERE ((date >= '$from') AND (date <= '$to'))";
$query = "SELECT * FROM v88374 WHERE date >= DATE_FORMAT('" . $from . "', '%Y%m%d') AND date <= DATE_FORMAT('" . $to . "', '%Y%m%d')";
//$query = "SELECT * FROM v88374 WHERE date >= DATE_FORMAT($from) AND date <= DATE_FORMAT($to)";
$export = mysql_query ($query ) 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 ) . "
";
}
$data = str_replace( "" , "" , $data );
if ( $data == "" )
{
$data = "
(0) Records Found!
";
}
print "$header
$data";
exit();
The $to and $from are parameters for searching for date range in the database. So we can leave that alone.