I do wanted to extract certain values from database to reload files into new server. I could do copy and paste from old server into new one, but I do not wanted to have old files that are no longer in use there. So that's what I'm trying to do.
In this products_description
table, it stored HTML codes.
I wanted to pulled off the following substring:
/zc156/product_pdf/[manufacturer]/[name].pdf
/zc156/product_img/[manufacturer]/[name].jpg
/zc156/product_img/[manufacturer]/[name].png
I did managed to obtained most (if not all PDFs) files by using the following 2 queries...
For first PDF file
SELECT
SUBSTRING(`products_description`.`products_description`,
LOCATE('/zc156/product_pdf/', `products_description`.`products_description`),
LOCATE('.pdf', `products_description`.`products_description`) - LOCATE('/zc156/product_pdf/', `products_description`.`products_description`) + 4)
AS 'ProductFile' FROM `products_description`
INNER JOIN `products` ON `products`.`products_id` = `products_description`.`products_id`
WHERE CONVERT(`products_description` USING utf8) LIKE '%/zc156/product_pdf/%'
AND `products`.`products_status` = 1
For the rest of PDF files
SELECT
SUBSTRING(`products_description`.`products_description`,
LOCATE('</a>', `products_description`.`products_description`),
LOCATE('</tr>', `products_description`.`products_description`) - LOCATE('</a>', `products_description`.`products_description`))
AS 'ProductFile' FROM `products_description`
INNER JOIN `products` ON `products`.`products_id` = `products_description`.`products_id`
WHERE CONVERT(`products_description` USING utf8) LIKE '%/zc156/product_pdf/%'
AND `products`.`products_status` = 1
However, when it comes to pull off JPG or PNG filenames... It's rougher to do substring as image filenames are span more than one cells and they repeated in certain pattern... I tried to search here and I found this topic.
Extract substring with a specific pattern in MySql
So, I tried to put some of my own data... but my result is not what I wanted. SQL Fiddle Attempt
Therefore, I wonder if there is a cleaner way to do this. Possibly may have to stack with couple substring
and/or left
function.