cTak Posted May 3, 2007 Share Posted May 3, 2007 Hello, I am helping a friend setup an eCommerce store with Zen cart, he added all of the products and uploaded the images, but a lot of them are .bmp files. I have downloaded them and converted them to web friendly jpgs, but the database is still calling for the .bmp files. Anyone have an SQL code I can use to update the "product_images" coulum so that *.bmp is changed to *.jpg? Something like this, but this does not work because there is a filename in front of the extension. UPDATE zen_products SET products_image = "jpg" WHERE products_image = "bmp" Thanks! Link to comment https://forums.phpfreaks.com/topic/49802-solved-help-how-to-change-batch-of-bmp-to-jpg-in-database/ Share on other sites More sharing options...
fenway Posted May 3, 2007 Share Posted May 3, 2007 You can use a regex/substring() to see if this piece appears at the end of the string, and then simply replace it. Link to comment https://forums.phpfreaks.com/topic/49802-solved-help-how-to-change-batch-of-bmp-to-jpg-in-database/#findComment-244455 Share on other sites More sharing options...
cTak Posted May 5, 2007 Author Share Posted May 5, 2007 Thanks for the reply. I am fairly new to this but learning quickly. Can you give me an example of a command to run? Something that would change *.gif to *.jpg ? Link to comment https://forums.phpfreaks.com/topic/49802-solved-help-how-to-change-batch-of-bmp-to-jpg-in-database/#findComment-245965 Share on other sites More sharing options...
bubblegum.anarchy Posted May 5, 2007 Share Posted May 5, 2007 SELECT replace(col_name, '.gif', '.jpg') FROM tab_name; Link to comment https://forums.phpfreaks.com/topic/49802-solved-help-how-to-change-batch-of-bmp-to-jpg-in-database/#findComment-245975 Share on other sites More sharing options...
cTak Posted May 5, 2007 Author Share Posted May 5, 2007 Showing rows 0 - 29 (3169 total, Query took 0.0005 sec) SQL query: SELECT REPLACE ( `products_image` , '.gif', '.jpg' ) FROM zen_products LIMIT 0 , 30 I did what you said bubblegum.anarchy, it shows the first 30 rows changed, but it doesn't save the changes? What do I do from here? Link to comment https://forums.phpfreaks.com/topic/49802-solved-help-how-to-change-batch-of-bmp-to-jpg-in-database/#findComment-246000 Share on other sites More sharing options...
bubblegum.anarchy Posted May 5, 2007 Share Posted May 5, 2007 Use the UPDATE statement (backup the table first): UPDATE zen_products SET products_image = replace(products_image, '.gif', '.jpg') Link to comment https://forums.phpfreaks.com/topic/49802-solved-help-how-to-change-batch-of-bmp-to-jpg-in-database/#findComment-246003 Share on other sites More sharing options...
fenway Posted May 5, 2007 Share Posted May 5, 2007 Use the UPDATE statement (backup the table first): UPDATE zen_products SET products_image = replace(products_image, '.gif', '.jpg') Strictly speaking, that's not very robust, since that substring could appear anywhere in the products_image string (although unlikely) -- hence my suggestion of a regex. Link to comment https://forums.phpfreaks.com/topic/49802-solved-help-how-to-change-batch-of-bmp-to-jpg-in-database/#findComment-246102 Share on other sites More sharing options...
bubblegum.anarchy Posted May 5, 2007 Share Posted May 5, 2007 Strictly speaking, that's not very robust, since that substring could appear anywhere in the products_image string (although unlikely) -- hence my suggestion of a regex. Yes, off coarse fenway - I recently developed a habit of naming images with dot seperators like btn.edit.gif so an image named btn.giffer.gif would end up being named btn.jpgfer.jpg - but as you suggest, unlikely. MySQL really should apply full regular expressions so something like UPDATE table SET value = REGEXP '/(.+)\.gif$/\1.jpg/i' could be performed. Link to comment https://forums.phpfreaks.com/topic/49802-solved-help-how-to-change-batch-of-bmp-to-jpg-in-database/#findComment-246375 Share on other sites More sharing options...
fenway Posted May 6, 2007 Share Posted May 6, 2007 True, but the where clause could simply make sure that the substring was 4 characters from the end before the update. Link to comment https://forums.phpfreaks.com/topic/49802-solved-help-how-to-change-batch-of-bmp-to-jpg-in-database/#findComment-246650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.