mysql - No data from the database after the files downloaded -
i want display data on particular condition of table after user enters data want display. failed display data. confused fault lies. looks variable $thn = $ _post['thn'], $bln = $ _post['bln'], $periode = $ _post['periode'] empty. please help.
i have 4 files. here codes:
1.absen_xls.php:
<?php include '../../inc/inc.koneksi.php'; ini_set('display_errors', 1); ini_set('error_reporting', e_error); include '../../excel/phpexcel.php'; include '../../excel/phpexcel/iofactory.php'; $table = 'absen_karyawan'; $bln = $_post['bln']; //this not work, don't know why? $thn = $_post['thn']; //this not work, don't know why? $periode = $_post['periode']; //this not work, don't know why? $where = "where tahun = '$thn' , bulan = '$bln' , periode = '$periode'"; // create new phpexcel object $objphpexcel = new phpexcel(); $sql = "select namakaryawan,tahun,bulan,periode,absen $table $where"; $query = mysql_query($sql); // bold $objphpexcel->getactivesheet()->getstyle("a2:c2")->applyfromarray(array("font" => array( "bold" => true))); // add data $objphpexcel->setactivesheetindex(0) ->setcellvalue('a2', 'no') ->setcellvalue('b2', 'nama') ->setcellvalue('c2', 'kehadiran'); $baris = 3; $no = 0; while($row=mysql_fetch_array($query)){ $no = $no +1; $objphpexcel->setactivesheetindex(0) ->setcellvalue("a$baris", $no) ->setcellvalue("b$baris", $row['namakaryawan']) ->setcellvalue("c$baris", $row['absen']); $baris = $baris + 1; } //border $border = $baris - 1; $stylearray = array( 'borders' => array( 'allborders' => array( 'style' => phpexcel_style_border::border_thin ) ) ); $objphpexcel->getactivesheet()->getstyle('a2:c'.$border)->applyfromarray($stylearray); unset($stylearray); //width $objphpexcel->getactivesheet()->getcolumndimension("a")->setwidth(5); $objphpexcel->getactivesheet()->getcolumndimension("b")->setwidth(20); $objphpexcel->getactivesheet()->getcolumndimension("c")->setwidth(15); //align center $objphpexcel->getactivesheet()->getstyle('a2:c'.$border)->getalignment()->sethorizontal(phpexcel_style_alignment::horizontal_center); // rename sheet $objphpexcel->getactivesheet()->settitle('absen'); // set active sheet index first sheet, excel opens first sheet $objphpexcel->setactivesheetindex(0); // redirect output client’s web browser (excel5) header('content-type: application/vnd.ms-excelformats-officedocument.spreadsheetml.sheet'); header('content-disposition: attachment;filename="absen.xlsx"'); header('cache-control: max-age=0'); $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel2007'); $objwriter->save('php://output'); exit; ?>
2.ajax.php:
// javascript document $(document).ready(function(){ $(function(){ $('button').hover( function() { $(this).addclass('ui-state-hover'); }, function() { $(this).removeclass('ui-state-hover'); } ); }); $("#tampil_data").load('modul/lap-absen/tampil_data.php'); $("#print").click(function(){ var thn = $("#thn").val(); var bln = $("#bln").val(); var periode = $("#periode").val(); cetakabsen(thn,bln,periode); }); function cetakabsen(c1,c2,c3){ var thn = c1; var bln = c2; var periode = c3; $.ajax({ type : "post", url : "modul/lap-absen/absen_xls.php", data : "thn="+thn+"&bln="+bln+"&periode="+periode, success : function(data){ window.open('http://localhost/gudang/modul/lap-absen/absen_xls.php'); } }); } });
change function one:
function cetakabsen(c1,c2,c3){ var thn = c1; var bln = c2; var periode = c3; var data = "thn="+thn+"&bln="+bln+"&periode="+periode; window.open('http://localhost/gudang/modul/lap-absen/absen_xls.php?'+data); }
and receive values in absen_xls.php:
$bln = mysql_real_escape_string($_get['bln']); $thn = mysql_real_escape_string($_get['thn']); $periode = mysql_real_escape_string($_get['periode']);
ps: go mysqli or pdo, dont use mysql extension.
Comments
Post a Comment