Tab delimited

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steveadams
Forum Newbie
Posts: 8
Joined: Wed Nov 18, 2009 10:09 am

Tab delimited

Post by steveadams »

Hi Guys

I'm new to php so please help me out.

I am extracting data into a csv file but for the life of me I dont know where to put the delimiter (tab).

Please help!

Code: Select all

 
$count = mysql_num_rows($result);
$fields= mysql_num_fields($result);
$data = "";
for ($i=0; $i < $fields; $i++) {
$field = mysql_fetch_field($result, $i);
$data .= $field->name;
$data .= "t";
}
$data .= "n";
while ($row=mysql_fetch_row($result)) {
for($x=0; $x < $fields; $x++) {
$field->name=$row[$x];
$data .= $field->name = $row[$x];
$data .= "t";
}
$data .= "n";
}
echo $data;
 
Thanks
Steve
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Tab delimited

Post by McInfo »

PHP Manual: Double Quoted Strings, Escaped Characters

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 3:20 pm, edited 1 time in total.
steveadams
Forum Newbie
Posts: 8
Joined: Wed Nov 18, 2009 10:09 am

Re: Tab delimited

Post by steveadams »

Thanks but it still doesn't work. The field that is causing the problem contains html. any suggestions?
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: Tab delimited

Post by morris520 »

Hi
your problem seems to be the delimiter.
1 - csv using comma not '/t'. check out what is a csv.
2 - "n" doesn't give you a line break to create a new row. Using "\n" instead. "\t" doesn't work in csv
3 - don't have command in your fields.
4 - echo doesn't build the csv file, unless you are trying to print what you've got here.

Hope this helps
Morris
Post Reply