Jump to content

Plese help populating database


lingo5
Go to solution Solved by Christian F.,

Recommended Posts

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 by lingo5
Link to comment
Share on other sites

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`
Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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'

 

......

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.