0

Hello world,
I need your help/advice, I have a table last_acces where inserting a few data. The table columns are:

Id
Name
Date

I want to export this data into excel clicking on the link or button from the page. Anyone could help me on this please? The action will select data from this table and export the result into excel file.

Thanks in advance

4
Contributors
6
Replies
11
Views
7 Years
Discussion Span
Last Post by rpv_sen
0

to create it in excel, you may need some library files. I have never used that though.

I used to export data in csv format, which you can easily open in excel. Also you can do it using standard file write operation. no external libraries needed.

0

to create it in excel, you may need some library files. I have never used that though.

I used to export data in csv format, which you can easily open in excel. Also you can do it using standard file write operation. no external libraries needed.

Thanks a lot for your replay; can you give me some example please of how to export in CSV file?

0

You action page may be like following. this page may be called from html form.

<?php

	$file_name="export.csv";
	$filter=" WHERE COL1='{$_POST['text1']}' AND col2='{$_POST['text2']}' ";


	$titlelist="";

	$titlelist="col1,col2,col3";

	{
	    header("Content-type: application/vnd.ms-excel");
		header('Content-Disposition: attachment; filename="'.$file_name.'"');
	 
/*
		--write proper data fetch syntax
		$query= "select col1,col2,col3 from mytable {$filter} order by col1");
		$stid=execute($query);

*/		
		print $titlelist.chr(13).chr(10);
		while ($row = oci_fetch_assoc($stid))
		{
 		    print "{$row['col1']}, {$row['col2']}, {$row['col3']}";
			print chr(13).chr(10);
		}
	}
    exit ();
?>
0

Hi

we will export excel file with help of phpclass and we can store the file in any path of your system.

0

Hi

Pls fill the below requirement and run the file, you will get csv file

<?php
$host = '';
$user = '';
$pass = '';
$db = '';
$table = '';
$file = '';

$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("Y-m-d_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;
?>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.