【发布时间】:2011-08-29 01:58:42
【问题描述】:
我以为我可以自己解决这个问题,但显然我正在努力解决这个问题。我原来有以下代码:
$query = "SELECT cards.card_id,title,description,meta_description,seo_keywords,price FROM cards,card_cheapest WHERE cards.card_id = card_cheapest.card_id ORDER BY card_id";
$result = mysql_query($query);
// Open file for writing
$myFile = "googleproducts.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
// Loop through returned data and write (append) directly to file
fprintf($fh, "%-200s %-200s %-800s %-200s %-800s\n", "id", "label","description","price","seo keywords");
fprintf($fh, "\n");
while ($row = mysql_fetch_assoc($result)) {
fprintf($fh, "%-200s %-200s %-800s %-200s %-800s\n", $row['card_id'], $row['title'], $row['description'],$row['price'], $row['seo_keywords']);
}
// Close out the file
fclose($fh);
?>
当文件打印到文本文件时,我需要做的是在标题中添加“By Amy”,所以我想我会像这样连接它:
$query = "SELECT cards.card_id,concat(title, "By Amy"),description,meta_description,seo_keywords,price FROM cards,card_cheapest WHERE cards.card_id = card_cheapest.card_id ORDER BY card_id";
每次我尝试运行该文件时,都会收到一条错误消息“(!) Parse error: syntax error, unexpected T_STRING in C:\wamp\www\output.php on line 22”。我知道该查询在我的 sequel pro 中有效,但是当我尝试将它合并到实际文件中时,它会归档
【问题讨论】:
标签: php mysql concatenation