在php中连接mysql的两个字段 [英] concatenate two fields of mysql in php
本文介绍了在php中连接mysql的两个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 mysql 数据库表中的字段是 imgpath
和 imgname
.我的图片路径是images/man/caps/
,图片名称是sun-cap.png
.现在我想通过这个查询选择他们两个
I have fields in mysql database table caps that are imgpath
and imgname
. My image path is images/man/caps/
and image name is sun-cap.png
. Now what I want to pick both of them via this query
select imgpath, imgname from caps;
现在如何将它们连接起来并在 php 中显示,以便输出可能像这样
Now how to concatenate them and display it in php so the output be might like this
images/man/caps/sun.cap.png
images/man/caps/sun.cap.png
推荐答案
用作
$result = mysql_query('select concat(imgpath, imgname) as img from caps');
while ($row = mysql_fetch_assoc($result)){
echo $row['img'];
}
这篇关于在php中连接mysql的两个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文