Page 1 of 1

Tab delimited

Posted: Thu Nov 19, 2009 8:45 am
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

Posted: Thu Nov 19, 2009 9:45 am
by Jonah Bron

Re: Tab delimited

Posted: Fri Nov 20, 2009 2:51 pm
by McInfo
PHP Manual: Double Quoted Strings, Escaped Characters

Edit: This post was recovered from search engine cache.

Re: Tab delimited

Posted: Sun Nov 22, 2009 11:20 am
by steveadams
Thanks but it still doesn't work. The field that is causing the problem contains html. any suggestions?

Re: Tab delimited

Posted: Sun Nov 22, 2009 3:48 pm
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