Prepand And Replace In One Query Mysql
I'm explaining with an example for getting my solution.
I've a user table having
id, name, image fields.
Sample record should be,
id - 1 name - TestUser image - temp/testuser.jpg (sometimes no sub-directory 'temp'. ie, image - testuser.jpg)
After user registers, I'm moving the image to a new subdirectory.
ie, moving from
So I need to update with the new url.
ie, I need two operations on here. Replace the sub-directory
1, if no sub-directory prepend '1/' to the existing image url.
How can I manage these operations in one query? Kindly help me :)
I recommend using the following query
update users set image = concat('new_dir/', substring(image from locate('/', image) + 1)) where id = 1
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?