是否可以自定義從mysql數據庫返回的字符串? 我有一個字段是圖像名稱,我想加入它與我的目錄路徑。如何自定義字符串返回
SELECT * FROM brand
//row return.
id image_name
1 image1.jpg
//i would like to have my return like
id image_name
1 upload/image1.jpg
是否可以自定義從mysql數據庫返回的字符串? 我有一個字段是圖像名稱,我想加入它與我的目錄路徑。如何自定義字符串返回
SELECT * FROM brand
//row return.
id image_name
1 image1.jpg
//i would like to have my return like
id image_name
1 upload/image1.jpg
嘗試此查詢:
SELECT id,
CONCAT('upload/', image_name) AS `file_name`
FROM band
使用CONCAT()函數來定製你的字符串,你想要的。
http://sqlfiddle.com/#!2/a2581/4317
select id, concat('upload', image_name) from tbl;
這裏是源http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat
是相同的所有文件的目錄路徑? – Srinivas
是的,它是一樣的 –