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 #170049 is a reply to message #170048] Thu, 07 October 2010 12:41 Go to previous messageGo to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma:
Senior Member
On 10/7/2010 8:19 AM, "Álvaro G. Vicario" wrote:
> 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().
>
>

Good point! From the manual (www.php.net):
array mysql_fetch_array ( resource $result [, int $result_type =
MYSQL_BOTH ] )

so the default is for both.

This would work if you added MYSQL_NUM as the optional second argument
-- or as you correctly stated just use mysql_fetch_row.

--
Shelly
[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: Sat Nov 30 09:52:31 GMT 2024

Total time taken to generate the page: 0.04918 seconds