Jump to content

Remove extra data within meta value...


Oran223
Go to solution Solved by kicken,

Recommended Posts

Hi ...

I have a database that hold the images in a strange way and to import them I need to clear the extra data sitting around them.

The meta_value is as follows

[{"id":"31768","imageurl":"https://sampledomain.com/wp-content/uploads/2021/10/904002d0f93c473a98f586302ccbd67d_ful.jpg"},{"id":"31766","imageurl":"https://sampledomain.com/wp-content/uploads/2021/10/5720254985644cb9a6679e258b74a202_ful.jpg"},{"id":"31767","imageurl":"https://sampledomain.com/wp-content/uploads/2021/10/155aa9070ad6404586a50e865be43a17_ful.jpg"},{"id":"31765","imageurl":"https://sampledomain.com/wp-content/uploads/2021/10/10ba1f392a7b401087e6d1ede995057b_ful.jpg"}]

but I need it as this (simply the image url separated by a comma) .... 

https://sampledomain.com/wp-content/uploads/2021/10/904002d0f93c473a98f586302ccbd67d_ful.jpg,https://sampledomain.com/wp-content/uploads/2021/10/5720254985644cb9a6679e258b74a202_ful.jpg,https://sampledomain.com/wp-content/uploads/2021/10/155aa9070ad6404586a50e865be43a17_ful.jpg, https://sampledomain.com/wp-content/uploads/2021/10/10ba1f392a7b401087e6d1ede995057b_ful.jpg

Using wildcards is there a way to be able clean/remove the unwanted data???  I have had a go but my knowledge of MySQL is not that advanced.

Many thanks in advance.

 

Link to comment
Share on other sites

  • Solution

The original data is JSON. If the " is actually part of the data and not a copy/paste issue here, then it's been run through htmlentities() or similar and you'll need to reverse that.

If you're using a new enough version of mysql, you could potentially use json_extract to get the URLs.

select json_extract(replace(jsonColumn, '"','"'), '$[*].imageurl')

Otherwise, you'd probably just want to select the column, and parse and extract the data as you fetch results in your code.

 

Edited by kicken
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.