/    Sign up×
Community /Pin to ProfileBookmark

how to export a dblist to excel file?

i want to export my dblist to excel format. how to achieve this. thnx for ur valuable suggestions.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@sebconnJun 08.2005 — it would be much easier to write information to a csv file, which opens perfectly fine in excel, you'll find most sites that want the function you are looking for do this.

the best way is not to save a csv file on your server for people to download. use headers, this allows you to output dynamic data and let users save it easily

for example:

[code=php]

<?php
// We'll be outputting a CSV
header('Content-type: text/csv');
// It will be called data.csv
header('Content-Disposition: attachment; filename="data.csv"');

//output data
echo "NAME, ADDRESS, PHONEn";
echo "Joe Bloggs, 765 Fake St, 55512345n";
?>

[/code]


to test it out, simply paste the above into a php file and test it out, works like a charm.

the output data can be adapted for database output easily, say ifyou were using mysql you'd use

[code=php]

//output data

echo "NAME, ADDRESS, PHONEn";

$query = mysql_query("SELECT * FROM addressbook");

while( $row = mysql_fetch_array($query) ) {

echo "$row[name], $row[address], $row[phone]n";

}

[/code]
×

Success!

Help @hifibee spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...