我想我可以自己弄清楚這一點,但顯然我正在努力。我原本下面的代碼:Concat Help:在mysql/php中添加字符串到查詢中
$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);
?>
我需要什麼做的是增加「艾米」當文件被打印到一個文本文件的標題,所以我認爲是我wouldconcat它像這樣:
$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";
每當我嘗試運行該文件時,我會在第22行的C:\ wamp \ www \ output.php中出現錯誤,說明「(!)解析錯誤:語法錯誤,意外的T_STRING」。我知道該查詢在我的續集親,但當我試圖將其納入實際的文件中它的文件
不幸的是,當我加入了$ query = 「SELECT cards.card_id,CONCAT(標題,\」 艾米\「), 描述,meta_description,seo_keywords,價格 從銀行卡,card_cheapest WHERE cards.card_id = card_cheapest.card_id ORDER BY card_id「;我收到以下結果: (!)注意:未定義的索引:第38行的C:\ wamp \ www \ output.php中的標題我是否需要更改最後的fprintf以反映此更改? – 2011-05-19 17:35:09
是的。 'concat'改變字段名 - 我會編輯我的答案來幫助你。 – jedwards 2011-05-19 17:38:56