FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Send .csv file to browser
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Send .csv file to browser [message #170048 is a reply to message #170047] Thu, 07 October 2010 12:19 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 07/10/2010 14:08, Derek Turner escribió/wrote:
> On Thu, 07 Oct 2010 10:25:50 +0000, Derek Turner wrote:
>
>> <snip very useful material>
>>
>> Many thanks, Jerry, I'll give it a go and report back.
>
> <?php
> include("/home/cantabi1/admin_connect.php");
> $sql = "SELECT `givenName`, `familyName`, `email`, `mobile`, `landLine`
> FROM `member` WHERE `active` = 1";
> $result = mysql_query($sql, $conn) or die (mysql_error());
> if ($result) {
> $outfile = fopen('php://output', 'w');
> header('Content-Type: text/csv');
> header('Content-disposition: attachment; filename=data.csv');
> while ($row = mysql_fetch_array($result)) {
> fputcsv($outfile, $row);
> }
> fclose($outfile);
> }
> ?>
>
> Produces a csv file just fine BUT each variable is doubled up i.e.
> Derek,Derek,Turner,Turner, etc. can anyone see why?

Try this and you'll see why:

while ($row = mysql_fetch_array($result)) {
print_r($result);
}

You can just use mysql_fetch_row().


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: file access permission?
Next Topic: Process queue without cron jobs
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 05:31:02 GMT 2024

Total time taken to generate the page: 0.04388 seconds