Nadat script gefinisht is redirecten
Ik heb hier een script dat een tabel uit de database pakt en exporteert naar de gebruiker .csv die die dan automatisch downloadt, maar nu wil ik als het script klaar is dat die dan redirect naar mijn truncate script.
Hoe moet ik dat doe of truncate er in bouwen?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
$host = 'db.jansented.nl'; // <-- db address
$user = '*****'; // <-- db user name
$pass = '*****'; // <-- password
$db = '****'; // db's name
$table = 'urenverantwoording'; // table you want to export
$file = 'output'; // csv name.
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field'].";";
$i++;}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}
$filename = $file."_".date("d-m-Y_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
$host = 'db.jansented.nl'; // <-- db address
$user = '*****'; // <-- db user name
$pass = '*****'; // <-- password
$db = '****'; // db's name
$table = 'urenverantwoording'; // table you want to export
$file = 'output'; // csv name.
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field'].";";
$i++;}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}
$filename = $file."_".date("d-m-Y_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
Gewijzigd op 20/07/2012 22:29:19 door Ted Jansen
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /public/sites/intranet.jansented.nl/exportclean/export.php:36) in <b>/public/sites/intranet.jansented.nl/exportclean/export.php</b> on line <b>38</b><br /> die error krijg ik nu!
Hoe kan ik anders de tabel truncaten nadat de CSV file is "gedownloadt"
Je kunt toch gewoon de code van het verwijderen als laatste in je script plaatsen? Uiteraard wel voor je exit.