mysql - php generating csv file only works first time -



mysql - php generating csv file only works first time -

i've next script:

<?php //define basepath codeigniter define('basepath', '/'); //include constants.php config file codeigniter require_once "../../my_manager/system/application/config/constants.php"; //check username , password if( $_get['username'] != import_username || $_get['password'] != import_password ) { header('http/1.0 401 unauthorized'); echo "denied access"; return; } //running scripts include 'export_table1.php'; include 'export_table2.php'; include 'export_table3.php'; include 'export_table4.php'; ?>

eache export following:

<?php //$host="localhost"; $host=""; $user=""; $pass=""; $db_name=""; $table="table1"; $conn = mysqli_connect($host,$user,$pass,$db_name) or die("connection error"); $query = "select * $table order id"; $result = mysqli_query($conn,$query) or die("sql error"); if(mysqli_num_rows($result)>0) { $csv = ""; $row = mysqli_fetch_assoc($result); $delim = ""; //retrieving first line fields foreach($row $k => $v) { $csv .= $delim . '"' . str_replace('"', '""', $k) . '"'; $delim= ";"; } $csv .= "\n"; //retrieving value fields while($row = mysqli_fetch_assoc($result)) { $delim = ""; foreach($row $v) { $csv .= $delim . '"' . str_replace('"', '""', $v) . '"'; $delim = ";"; } $csv .= "\n"; } header("content-type: text/csv"); header("content-disposition: attachment; filename=".$table.".csv"); echo $csv; exit } else { echo "no records"; } exit ?>

the issue first script fired, can first table downloaded csv file. if launch first table2 export, table2 export fired. how can manage that? in advance!

as far know "exit" kills both child- , parent-script - that's cause why first table exported in csv. utilize "return" instead continue.

php mysql csv export-to-csv

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -