How do you export as TXT Tab Delimited from MySQL

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

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

Post by simonmlewis »

Please see my edit. I did change it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do you export as TXT Tab Delimited from MySQL

Post by Celauran »

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

Post by simonmlewis »

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'>";
	}
	?>
This errors: [text]Parse error: syntax error, unexpected ';' in C:\xampp\phpMyAdmin\site\txt_googleproducts.php on line 29[/text]
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do you export as TXT Tab Delimited from MySQL

Post by Celauran »

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

Post by simonmlewis »

What do you mean?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do you export as TXT Tab Delimited from MySQL

Post by Celauran »

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

Post by simonmlewis »

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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do you export as TXT Tab Delimited from MySQL

Post by Celauran »

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

Post by simonmlewis »

Bingo!
Love PHP. Love CSS. Love learning new tricks too.
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

Post by simonmlewis »

Well having got that working my end, Google then told me this:

Code: Select all

Your items contain more attributes than those specified in the header row. 
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".
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do you export as TXT Tab Delimited from MySQL

Post by Celauran »

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

Post by simonmlewis »

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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply