sajid
sajid

Reputation: 257

concatenate two fields of mysql in php

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;

Now how to concatenate them and display it in php so the output be might like this

images/man/caps/sun.cap.png

Upvotes: 1

Views: 7291

Answers (4)

Uday Sawant
Uday Sawant

Reputation: 5798

If you are getting the concatenated string from MySQL itself like stated by @xdazz then simply echo it like

echo $row['img'];

else if you are using query like select imgpath, imgname from caps; use

echo $row['imgpath'].$row['imgname'];

Upvotes: 0

Dau
Dau

Reputation: 8848

use it as

$result = mysql_query('select concat(imgpath, imgname) as img from caps');
while ($row = mysql_fetch_assoc($result)){
 echo $row['img'];
}

Upvotes: 0

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230306

Something like this:

 select concat(imgpath, imgname) from caps;

Upvotes: 0

xdazz
xdazz

Reputation: 160833

select concat(imgpath, imgname) as img from caps;

Upvotes: 3

Related Questions