lingo5 Posted April 5, 2013 Share Posted April 5, 2013 (edited) Hi, I have a table like this id_articulo int(11) id_subcategoria int(11) articulo_tit varchar(80) articulo_precio double(15,3) id_categoria int(11) articulo_descripcion text articulo_imagen varchar(255) articulo_visible tinyint(1) articulo_novedad tinyint(1) articulo_oferta tinyint(1) I need to write a query that updates the articulo_imagen column with the path to the image, where the image name should be id_articulo.jpg ie: ../uploads/28.jpg can this be done? thanks Edited April 5, 2013 by lingo5 Quote Link to comment Share on other sites More sharing options...
Christian F. Posted April 5, 2013 Share Posted April 5, 2013 Took be a couple of reads, but I think I got what you're looking for. Sounds like you've moved the location of all/some of the images, and now want to update the database to reflect this. Is this correct? If you want to only update the images which has the same name as the article ID: UPDATE `table` SET `articulo_imagen` = CONCAT('$path',`id_articulo`) WHERE `articulo_imagen` = `id_articulo` Quote Link to comment Share on other sites More sharing options...
lingo5 Posted April 5, 2013 Author Share Posted April 5, 2013 hi Christian, well the problem is I have a database where all the image paths are "uploads/img/none.jpg" by default. Then I have the folder "uploads" with all the images named id_articulo.jpg where id_articulo is the value from this column (don't ask me why ..I've just inherited it like this...) What I need to do is replace "uploads/img/none.jpg" with "../uploads/id_articulo.jpg" for all my db rows with one single query. Do I make sense?..I can't test the query you suggested righ now but I have the feeling is not what I'm looking for..sorry I know my explanation sux... Quote Link to comment Share on other sites More sharing options...
Christian F. Posted April 5, 2013 Share Posted April 5, 2013 With some slight modifications, the query above should be exactly what you're looking for. Only thing you need to change, is the path and the value you're testing against in the WHERE clause. Oh, and the table name, of course. Quote Link to comment Share on other sites More sharing options...
mikosiko Posted April 5, 2013 Share Posted April 5, 2013 (edited) and don't forget to add the '.jpg' extension (or whichever one that you want) Edited April 5, 2013 by mikosiko Quote Link to comment Share on other sites More sharing options...
lingo5 Posted April 5, 2013 Author Share Posted April 5, 2013 so guys.... I've tried this UPDATE `t_articulos` SET `articulo_imagen` = CONCAT('../uploads/',`id_articulo`,`/.jpg`) to get this error Error Code : 1054 Unknown column '/.jpg' in 'field list' ...... Quote Link to comment Share on other sites More sharing options...
Solution Christian F. Posted April 5, 2013 Solution Share Posted April 5, 2013 Backticks is not the same as single quotes. Quote Link to comment Share on other sites More sharing options...
lingo5 Posted April 5, 2013 Author Share Posted April 5, 2013 silly me...THANKS it woked like a charm !!!! thanks christian you rule and mikosiko you too Quote Link to comment Share on other sites More sharing options...
Christian F. Posted April 5, 2013 Share Posted April 5, 2013 You're welcome, glad I could help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.