Saturday, 1 June 2013
Mysql datadase to Excel Sheet convertsion PHP script
PHP script for mysql database to excel can convert automatically the file run in browser.
Database, User name, Password, Table Name are included/mention here. Consider user requirements.
<?php
ob_start();
mysql_connect('localhost','root','');
mysql_select_db('test');
$sql = "SELECT * from log_attempts";
$res = mysql_query( $sql) or die();
$count = mysql_num_fields($res);
// fetch table header from database
$header = '';
for ($i = 0; $i < $count; $i++){
$header .= mysql_field_name($res, $i)."\t";
}
// fetch data each row, store on tabular row data
while($row = mysql_fetch_row($res)){
$line = '';
foreach($row as $value){
if(!isset($value) || $value == ""){
$value = "\t";
}else{
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
$data = str_replace("\r", "", $data);
}
$name=date('d-m-y').'-list.xls';
header("Content-type:application/vnd.ms-excel;name='excel'");
header("Content-Disposition: attachment; filename=$name");
header("Pragma: no-cache");
header("Expires: 0");
// Output data
echo $header."\n\n".$data;
?>
Subscribe to:
Post Comments (Atom)
Redux vs Redux Toolkit vs React Context
These are often confused. Feature Redux Redux Toolkit Context API Purpose State management Simplifies Redux Shares values in Rea...
-
How to iterate through multiple rows in jquery using ajax, json, and php ================================================= REF LINK : h...
-
Cross browser testing - automation framework-cypress,playwrite; CloudBorwser -saucelabs browserstackEvaluating cross-browser testing for a React application involves assessing both functional consistency (JavaScript/API behavior) and v...
No comments:
Post a Comment