roles))) { //echo “Admin is logged in “; } else { //echo “Admin not logged in “; header(“Location:$base_url”); } include ‘db_config.php’; //mysql_connect ( ‘localhost’, ‘ecadev’, ‘Ex#3xZU=G9[aK’ ) or die ( mysql_error () ); //mysql_select_db ( ‘ecadev_sure’ ); $get = mysql_query ( “select * from tbl_order ” ); if (isset($_POST[‘export_csv’])) { $date=$_POST[‘date’]; $type=$_POST[‘type’]; if ($type==”digital”) { $order_type=”0″; } else { $order_type=”1″; } if ($date==””) { $get1 = mysql_query ( “select * from tbl_order where order_type='”.$order_type.”‘” ); } else { if ($date==”today”) { $get1=mysql_query(“select * from tbl_order WHERE DATE(date_created) = CURDATE() and order_type='”.$order_type.”‘”); } elseif ($date==”week”) { $get1=mysql_query(“SELECT * FROM `tbl_order` WHERE date_created > DATE_SUB(NOW(), INTERVAL 1 WEEK) and order_type='”.$order_type.”‘”); } elseif ($date==”month”) { $get1=mysql_query(“SELECT * FROM `tbl_order` WHERE date_created > DATE_SUB(NOW(), INTERVAL 1 MONTH) and order_type='”.$order_type.”‘”); } else { $get1 = mysql_query ( “select * from tbl_order where order_type='”.$order_type.”‘” ); } } $results=array(); while($order_detail1s = mysql_fetch_array ( $get1 )) { $order_detail1 = json_decode ( $order_detail1s [‘order_detail’], true ); $results[]=$order_detail1[“item”]; } $fileName = “All-Orders-“.date(‘Y-m-d’).”.csv”; header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”); header(‘Content-Description: File Transfer’); header(“Content-type: text/csv”); header(“Content-Disposition: attachment; filename={$fileName}”); header(“Expires: 0”); header(“Pragma: public”); $fh = @fopen( ‘php://output’, ‘w’ ); $headerDisplayed = false; foreach ( $results as $data ) { // Add a header row if it hasn’t been added yet if ( !$headerDisplayed ) { // Use the keys from $data as the titles fputcsv($fh, array_keys($data)); $headerDisplayed = true; } $default = ‘——‘; $data=array_map( function($value) use ($default) { return $value ?: $default; }, $data ); // Put the data into the stream fputcsv($fh, $data); } // Close the file fclose($fh); // Make sure nothing else is sent, our file is done exit; } ?>
Digital Form Order Custom Form Order | Select Filter Today This Week This Month |