Answer the question
In order to leave comments, you need to log in
Why does a 500 Internal Server Error occur? How to fix?
I have a database of more than 2000 records and will be replenished!
on the page I display a table, 10 records per page + pagination everything is ok.
I made a button (file) for export!
here is the code for that pastebin file:
https://pastebin.com/FgQv3nZT
and here:
<?php
ini_set("max_execution_time", "3600"); // ожидаем
// // Игнорирует отключение пользователя и позволяет скрипту
// // быть запущенным постоянно
// ignore_user_abort(true);
// ini_set('error_reporting', E_ALL);
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
//require "auth.php";
//Инклюдим файл подключения с базой данных
include_once($_SERVER["DOCUMENT_ROOT"].'/db.php');
$getsort = $_GET['sort'];
if ($getsort === 'desc'){
$sort = 'desc';
}else{
$sort = 'asc';
}
$getkey = $_GET['key'];
if (!empty($getkey)) {
$key = $getkey;
}else{
$key = 'id';
}
$q=$db->query('SELECT * FROM `news` WHERE `show_in_feed`=1 ORDER BY `'.$key.'` '.$sort.' ');
require('classes/PHPExcel.php');
// Подключаем класс для вывода данных в формате excel
require_once('classes/PHPExcel/Writer/Excel5.php');
// Создаем объект класса PHPExcel
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize ' => '256MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$pExcel = new PHPExcel();
$pExcel->setActiveSheetIndex(0);
$aSheet = $pExcel->getActiveSheet();
$aSheet->setTitle('List');
//добавление данных
$aSheet->setCellValue("A1", "Added Date");
$aSheet->setCellValue("B1", "Title");
$aSheet->setCellValue("C1", "Threat Type");
$aSheet->setCellValue("D1", "Domain");
$aSheet->setCellValue("E1", "URL");
$rowCount = 2;
while($n=$q->fetch_assoc()){
$type_ed = explode(",", $n['threat_type']);
$type_edit = '';
foreach ($type_ed as $type_edd)
{
$ttt = $db->query("SELECT * FROM `type` WHERE `id`='".$type_edd."'")->fetch_assoc();
$name_type = $ttt['type'];
$type_edit.= "$name_type,";
}
$threat_type = substr($type_edit, 0, -1);
$aSheet->setCellValue("A".$rowCount, $n["added_date"]);
$aSheet->setCellValue("B".$rowCount, $n["title"]);
$aSheet->setCellValue("C".$rowCount, $threat_type);
$aSheet->setCellValue("D".$rowCount, $n["domain"]);
$aSheet->setCellValue("E".$rowCount, $n["full_url"]);
$rowCount++;
}
//форматирование
$style_wrap = array( 'font' => array( 'bold' => true ) );
$aSheet->getStyle('A1:V1')->applyFromArray($style_wrap);
//отдаем пользователю в браузер
// include("classes/PHPExcel/Writer/Excel2007.php");
// $objWriter = new PHPExcel_Writer_Excel2007($pExcel);
$objWriter = new PHPExcel_Writer_Excel5($pExcel);
ob_clean();
// header('Cache-Control: max-age=0');
header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" );
header ( "Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT" );
header ( "Cache-Control: no-cache, must-revalidate" );
header ( "Pragma: no-cache" );
header ( "Content-type: application/vnd.ms-excel" );
header ( "Content-Disposition: attachment; filename=List.xls" );
$objWriter->save('php://output');
?>
type_ed = explode(",", $n['threat_type']);
$type_edit = '';
foreach ($type_ed as $type_edd)
{
$ttt = $db->query("SELECT * FROM `type` WHERE `id`='".$type_edd."'")->fetch_assoc();
$name_type = $ttt['type'];
$type_edit.= "$name_type,";
}
Answer the question
In order to leave comments, you need to log in
1) There is a log where all errors are written, IT IS NECESSARY TO LOOK, to look for a solution at the level of "something does not work, you have to poke your finger in different places" is stupid and inefficient.
2) If the log is not kept (which is of course strange, but possible), then the error logs must be enabled, the output can be omitted.
3)
type_ed = explode(",", $n['threat_type']);
$type_edit = '';
foreach ($type_ed as $type_edd)
{
$ttt = $db->query("SELECT * FROM `type` WHERE `id`='".$type_edd."'")->fetch_assoc();
$name_type = $ttt['type'];
$type_edit.= "$name_type,";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question