Monday, 3 July 2017

How to replace mysql select query parameter in query

table structure (tabme name= tbl_users)

id     name        image
1      Raju         raju.jpg
2      amar        amar.jpg
3      jay            jay.jpg


now I want to show full url to image like

id     name        image
1      Raju         http://localhost/uploads/raju.jpg
2      amar         http://localhost/uploads/amar.jpg
3      jay            http://localhost/uploads/jay.jpg


to achieve this we just have to write query as


$sql = "SELECT id, name, image, REPLACE( image, image, CONCATE( "http://localhost/uploads/", image ) ) AS newimage FROM `tbl_users`";


REPLACE(fieldname,'replace what', 'replace with')
CONCATE(field1,'field2' ..) 







banner
Previous Post
Next Post

0 comments: