Page 2 of 3
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Wed Sep 18, 2013 8:48 am
by simonmlewis
Code: Select all
<?php
$result = mysql_query("SELECT * FROM products WHERE pause = 'off'");
$date = "id\ttitle\tdescription\tprice\timage link\tlink\tcondition\tavailability\tbrand\n";
while($row = mysql_fetch_object($result))
{
$title = "$row->title";
$findtitle ="/ /";
$replacetitle ="-";
$titlereplace = preg_replace ($findtitle, $replacetitle, $title);
$categ = "$row->catname";
$findcateg ="/ /";
$replacecateg ="-";
$categreplace = preg_replace ($findcateg, $replacecateg, $categ);
$subcateg = "$row>subname";
$findsubcateg ="/ /";
$replacesubcateg ="-";
$subcategreplace = preg_replace ($findsubcateg, $replacesubcateg, $subcateg);
$data .= "{$row->id}\t{$row->title}\t{$row->title}\t{$row->price}\thttp://www.site.co.uk/images/{$row->image}\tURLHERE\tNew\tinstock\t{$row->manufacturer}\t\n";
}
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-disposition: attachment; filename="data.txt"');
echo $data;
exit;
?>
9 of both now, and $output is now $data, still outputs nothing.
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Wed Sep 18, 2013 8:51 am
by Celauran
You have $date instead of $data, but I also noticed you've removed the include that sets up the DB connection. Why not comment out the headers calls until you get the desired output on your screen?
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Wed Sep 18, 2013 8:56 am
by simonmlewis
It's only coz I didn't copy that bit in the "copy paste" for you - sorry.
I have commented the headers, and it's producing nothing.
Code: Select all
include "dbconn.php";
$result = mysql_query("SELECT * FROM products WHERE pause = 'off'");
$data = "id\ttitle\tdescription\tprice\timage link\tlink\tcondition\tavailability\tbrand\n";
while($row = mysql_fetch_object($result))
{
$title = "$row->title";
$findtitle ="/ /";
$replacetitle ="-";
$titlereplace = preg_replace ($findtitle, $replacetitle, $title);
$categ = "$row->catname";
$findcateg ="/ /";
$replacecateg ="-";
$categreplace = preg_replace ($findcateg, $replacecateg, $categ);
$subcateg = "$row>subname";
$findsubcateg ="/ /";
$replacesubcateg ="-";
$subcategreplace = preg_replace ($findsubcateg, $replacesubcateg, $subcateg);
$data .= "{$row->id}\t{$row->title}\t{$row->title}\t{$row->price}\thttp://www.site.co.uk/images/{$row->image}\tURLHERE\tNew\tinstock\t{$row->manufacturer}\t\n";
}
//header('Content-Type: application/octet-stream');
//header('Content-Transfer-Encoding: binary');
//header('Content-disposition: attachment; filename="data.txt"');
echo $data;
exit;
mysql_close($sqlconn);
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Wed Sep 18, 2013 8:59 am
by Celauran
Have you checked that $result actually contains a result set and isn't false? Is your error reporting on? It looks like it's failing silently somewhere. Even with no rows returned, $data is still being set, so should still produce some output on echo.
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Wed Sep 18, 2013 9:07 am
by simonmlewis
I spotted it: $subcateg = "$row>subname";.
Should I see the results from the DB on a new line AFTER the rows at the top? Or "inline"....?
ie...
.... availability brand
.....in stock Special
Or...
....availability brand in stock special
?
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Wed Sep 18, 2013 9:10 am
by Celauran
\n isn't going to display in-browser. It will look like one huge mess of text. It will display correctly in a text file, though.
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Wed Sep 18, 2013 9:14 am
by simonmlewis
The first line of the txt file displays like this (with wordwrap on):
id title description price image link link condition availability brand 3 XL Top XL Top 29.99
Should it now show in TXT as:
id title description price image link link condition availability brand
3 XL Top XL Top 29.99
(tho perhaps spaced properly)
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Wed Sep 18, 2013 9:19 am
by Celauran
Are you on a Windows machine? \n is a UNIX linefeed. Try \r\n or see if your text editor can recognize LF instead of CRLF
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Wed Sep 18, 2013 9:22 am
by simonmlewis
bingo!!
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Thu Sep 26, 2013 6:53 am
by simonmlewis
Problem: I need to set all the text to be titlecase, as Google doesn't like CAPITALS.
I tried this but it just echoes with the tags I enter - how do I make it use those tags without actually rendering them on the page?
Code: Select all
$data .= "{$row->id}\t<font style='text-transform: titlecase'>{$row->title}</font>\t
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Thu Sep 26, 2013 6:56 am
by Celauran
Code: Select all
$data .= "{$row->id}\t" . ucwords($row->title) . "\t";
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Thu Sep 26, 2013 7:03 am
by simonmlewis
Code: Select all
$data .= "{$row->id}\t" . ucwords{$row->title} . "\t" . ucwords{$row->title} . "\t{$row->price}
Code: Select all
$data .= "{$row->id}\t" . ucwords($row->title) . "\t" . ucwords($row->title) . "\t{$row->price}
Try both of these options, as I did the top one by accident.
The top one doesn't make it titlecase.
The second one makes the page produce nothing at all.
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Thu Sep 26, 2013 7:09 am
by Celauran
I'm assuming that's not the entire line and that you've got the closing double quote and the semicolon at line end? What error(s) does it display?
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Thu Sep 26, 2013 7:13 am
by simonmlewis
Sorry I was paraphrasing it:
Code: Select all
$data .= "{$row->id}\t" . ucwords($row->title) . "\t" . ucword($row->title) . "\t{$row->price}\thttp://www.site.co.uk/images/{$row->photoprimary}\thttp://www.site.co.uk/product/{$row->catid}/$categreplace/{$row->subid}/$subcategreplace/{$row->id}/$titlereplace\tNew\tinstock\t{$row->manufacturer}\t \r\n";
I am reading about ucwords, and it says that is sets the first character only to uppercase?
Sorry edit - this is the code with the (). Produces nothing, no errors.
Re: How do you export as TXT Tab Delimited from MySQL
Posted: Thu Sep 26, 2013 7:17 am
by Celauran
Code: Select all
$data .= "{$row->id}\t" . ucwords{$row->title} . "\t" . ucwords{$row->title} . "\t{$row->price}\thttp://www.site.co.uk/images/{$row->photoprimary}\thttp://www.site.co.uk/product/{$row->catid}/$categreplace/{$row->subid}/$subcategreplace/{$row->id}/$titlereplace\tNew\tinstock\t{$row->manufacturer}\t \r\n";
ucwords is a function; you need to use parentheses, not braces.
simonmlewis wrote:I am reading about ucwords, and it says that is sets the first character only to uppercase?
It says no such thing. From the manual:
Returns a string with the first character of each word in str capitalized, if that character is alphabetic.