How do you export as TXT Tab Delimited from MySQL
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you export as TXT Tab Delimited from MySQL
Please see my edit. I did change it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you export as TXT Tab Delimited from MySQL
Assuming that second ucword is actually ucwords in your code, that should work. What errors is it producing?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you export as TXT Tab Delimited from MySQL
Code: Select all
<?php
$cookietype = $_COOKIE['type'];
$todaydate = date('Y-m-d');
if ($cookietype == "admin") {
include "dbconn.php";
$result = mysql_query("SELECT * FROM products WHERE pause = 'off'");
$data = "id\ttitle\tdescription\tprice\timage link\tlink\tcondition\tavailability\tbrand \r\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" . 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";
}
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-disposition: attachment; filename="data.txt"');
echo $data;
exit;
mysql_close($sqlconn);
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=index.php?page=a_login'>";
}
?>Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you export as TXT Tab Delimited from MySQL
What's the story with the opening parenthesis on line 28?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you export as TXT Tab Delimited from MySQL
What do you mean?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you export as TXT Tab Delimited from MySQL
Line 28 consists of an unmatched opening parenthesis that serves no apparent purpose. PHP doesn't know what to do with it.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you export as TXT Tab Delimited from MySQL
Ok, there are no now errors (found the odd ( in there) but it's still producing it all in CAPITALS.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you export as TXT Tab Delimited from MySQL
Ah, I didn't realize they were in all caps to begin with. You'll need to convert them to lower case first.
Code: Select all
ucwords(strtolower($row->title))-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you export as TXT Tab Delimited from MySQL
Bingo!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you export as TXT Tab Delimited from MySQL
Well having got that working my end, Google then told me this:
So I tried the previous version "with the capitals" and that too produces that said error.
They seem to move the goalposts all the time.
I'm thinking that error means, I have more items per row from the database, than there are in the header (title, condition etc), which is totally false. If anything it is the other way around where in some cases I don't have a "manufacturer".
Code: Select all
Your items contain more attributes than those specified in the header row. They seem to move the goalposts all the time.
I'm thinking that error means, I have more items per row from the database, than there are in the header (title, condition etc), which is totally false. If anything it is the other way around where in some cases I don't have a "manufacturer".
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you export as TXT Tab Delimited from MySQL
Try removing that last \t
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you export as TXT Tab Delimited from MySQL
Yep that did it.
Seems Google is making changes but I don't know how it ever passed through before as I didn't alter that.
Anyway, let's see if this gets accepted.
Thanks for your help again.
Seems Google is making changes but I don't know how it ever passed through before as I didn't alter that.
Anyway, let's see if this gets accepted.
Thanks for your help again.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.