Page 3 of 3

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

Posted: Thu Sep 26, 2013 7:18 am
by simonmlewis
Please see my edit. I did change it.

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

Posted: Thu Sep 26, 2013 7:20 am
by Celauran
Assuming that second ucword is actually ucwords in your code, that should work. What errors is it producing?

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

Posted: Thu Sep 26, 2013 7:26 am
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]

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

Posted: Thu Sep 26, 2013 7:41 am
by Celauran
What's the story with the opening parenthesis on line 28?

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

Posted: Thu Sep 26, 2013 7:44 am
by simonmlewis
What do you mean?

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

Posted: Thu Sep 26, 2013 7:46 am
by Celauran
Line 28 consists of an unmatched opening parenthesis that serves no apparent purpose. PHP doesn't know what to do with it.

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

Posted: Thu Sep 26, 2013 7:49 am
by simonmlewis
Ok, there are no now errors (found the odd ( in there) but it's still producing it all in CAPITALS.

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

Posted: Thu Sep 26, 2013 8:25 am
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))

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

Posted: Thu Sep 26, 2013 8:30 am
by simonmlewis
Bingo!

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

Posted: Thu Sep 26, 2013 9:36 am
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".

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

Posted: Thu Sep 26, 2013 10:19 am
by Celauran
Try removing that last \t

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

Posted: Thu Sep 26, 2013 11:29 am
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.