query( "SELECT a.created_at, b.staff_idno FROM staff_attendance a LEFT JOIN staff b ON ( a.staff_id = b.staff_id ) WHERE a.deleted_at IS NULL AND CHAR_LENGTH(b.staff_idno) > 6 " . $search_query . " ORDER BY a.created_at" ) ; $filename = '../txt/' . $today_datetime . '.txt' ; $file = fopen( $filename, "wb" ) ; fwrite($fp,$content); if ( $mysqli_attendances->num_rows > 0 ){ $count = 0 ; $total = $mysqli_attendances->num_rows ; while ( $row_attendances = $mysqli_attendances->fetch_assoc() ){ $count++ ; $content = $row_attendances['staff_idno'] . '|' . date( 'Y-m-d', strtotime($row_attendances['created_at']) ) . '|' . date( 'H:i:s', strtotime($row_attendances['created_at']) ) ; if ( $count != $total ){ $content .= "\n" ; } fwrite( $file, $content ) ; } } fclose( $file ) ; // header("Content-Description: File Transfer"); // header("Content-Type: application/octet-stream"); // header("Content-Disposition: attachment; filename=\"". basename($filename) ."\"") ; // readfile ( $filename ) ; echo 'Download' ; exit ; ?>