Jump to content


Photo

inserting tabs


  • Please log in to reply
7 replies to this topic

#1 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 06 July 2006 - 11:32 AM

If I do this:
$out="word1\tword2";
I get that when I fwrite it to file
if I do this:
$out="word1 \t word2";
I get word with the tab, but I get the space between word and the tab.
If I do this:
$tab="\t";
$out="word1".$t."word2"...
same problem

Q:  How do I set the $out so the column headers in the csv I'm making doesnt' have the extra spaces? It isn't a problem in the query return, but I'm doing that like this:

$out=$row[0]."\t".$row[1].... etc.


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 July 2006 - 11:38 AM

Try:
<?php $out = implode("\t",$row); ?>
This will put a tab character between each element of $row.

Ken

#3 CheesierAngel

CheesierAngel
  • Members
  • PipPipPip
  • Advanced Member
  • 105 posts
  • LocationBelgium

Posted 06 July 2006 - 11:39 AM

I know it isn't the best solution but it works:

$out = array();
foreach($row as $tmp) {
  array_push($out, $tmp);
}
$out = implode('\t', $out);


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 July 2006 - 11:43 AM

How are you outputting $out?

If you are sending it to the browser the browser will not show the tab, but show a space between word1 and word2, howver if you look into the source you'lll see the tab is there. browser ignores white spaces characters.

If you are sending it a file then it should put a tab between word1 and word2

Or do you want it to to store \t in the file as is with out it creating a tab? If you dont want it to create a tab use this:
\\t instead, two backslashes.

#5 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 06 July 2006 - 11:48 AM

I have no problem witht he row returns... I can't get the tabs in the HEADERS for the csv file:

here is the script:

<?php
$OUTPUT='';
$i=0;
$tab='\t';
$file = "./VQ1.TXT";
$fp = fopen($file,"a");
//****** the next like is the problem
$OUTPUT = "line".$tab."it_date \t insptype \t process \t product \t serialno \t step \t step_desc \t hi \t lo \t units \t actual \t gonogo \t passed";
//****** everything from here down is fine...
fwrite($fp, $OUTPUT."\n");
$connect = odbc_connect("QES9000", "", "");
$query = "SELECT
    itdatshta.`it_date`, itdatshta.`insptype`, itdatshta.`process`, itdatshta.`product`, itdatshta.`serialno`, itdatshta.`failed`,
    itdatshtda.`descr`, itdatshtda.`hi`, itdatshtda.`lo`, itdatshtda.`units`, itdatshtda.`actual`, itdatshtda.`gonogo`, itdatshtda.`step`
FROM
    `itdatshta` itdatshta INNER JOIN `itdatshtda` itdatshtda ON
        itdatshta.`datshtid` = itdatshtda.`datshtid` AND
    itdatshta.`sample` = itdatshtda.`sample`
WHERE
    itdatshta.`product` like 'T%SS3%' AND
    (itdatshta.`process` = 'VQ Functional Outputs' OR
    itdatshta.`process` = 'VQ Functional Inputs' OR
    itdatshta.`process` = 'QA Evaluation' OR
    itdatshta.`process` = 'Functional Test') AND
    itdatshta.`failed` = 0 AND itdatshta.`it_date` < {d '2006-06-26'}
ORDER BY
    itdatshta.`it_date` ASC,
    itdatshta.`serialno` ASC,
    itdatshta.`process` ASC";

$result = odbc_do($connect, $query);
WHILE($row=odbc_fetch_array($result))
{

$OUTPUT = $i."\t".rtrim($row['it_date'])."\t".rtrim($row['insptype'])."\t".rtrim($row['process'])."\t".rtrim($row['product'])."\t".rtrim($row['serialno'])."\t".rtrim($row['step'])."\t".rtrim($row['descr'])."\t".rtrim($row['hi'])."\t".rtrim($row['lo'])."\t".rtrim($row['units'])."\t".rtrim($row['actual'])."\t".rtrim($row['gonogo'])."\t YES";
//$file = "./VQ1.TXT";
//$fp = fopen($file,"w");
fwrite($fp, $OUTPUT."\n");

}
fclose($fp);
odbc_close($connect);

?>

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 July 2006 - 11:53 AM

Put the header strings into an array and use the implode() technique I described earlier.
<?php
$hdr = array('line','it_date','insptype','process','product','serialno','step','step_desc','hi','lo','units','actual','gonogo','passed');
fwrite($fp, implode("\n",$hdr)."\n");
?>

Ken

#7 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 06 July 2006 - 12:06 PM

Thanks for spelling it out for me Ken, on that last post...



#8 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 July 2006 - 01:29 PM

I goofed on my last post .... the first "\n" in the implode() should be a "\t".

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users