Solved

downloading my database as a excel or text document

Posted on 2007-11-15
3
161 Views
Last Modified: 2008-01-08
I have a basic database user id, name, address, age. I want my user to go to www.myurl/download.php and download a copy of the database as a text or excel file in rows.

Is this possible?


Thanks,

R.
0
Comment
Question by:roscoeh23
  • 2
3 Comments
 
LVL 7

Expert Comment

by:dansoto
ID: 20289675
0
 

Author Comment

by:roscoeh23
ID: 20289875
this juut outputs it to the screen.
0
 
LVL 7

Accepted Solution

by:
dansoto earned 500 total points
ID: 20289942
You can try this then and just link to this script:

<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
include("dbconnect.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
$select = "SELECT * FROM db";
$export = mysql_query($select);
$count = mysql_num_fields($export);
for ($i = 0; $i < $count; $i++) {
$header .= mysql_field_name($export, $i)."\t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r", "", $data);
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
print "$header\n$data";
?>
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question