Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify many rows in a mysql database at the same time

I have a database with prices from lots of different products. They're all in this format: £25,000.

What I want is the following: 25000.

I figured I must use a foreach loop and use str_replace, but I can't seem to find a way to delete the pound sign and the comma.

I also have a few rows where the prices are missing, they're in the database as following: £00

Again, I want to delete the pound sign. So that must be a different loop I guess?

Could you explain how it must be done?

like image 400
Andre Avatar asked Feb 20 '23 14:02

Andre


2 Answers

try this

$new_array = str_replace(array("£",","),array("",""),$old_array);
like image 195
Nauphal Avatar answered Mar 03 '23 02:03

Nauphal


This will remove comma and £ (if present), in all your rows at once

update your_table
set your_column = replace(replace(your_column, '£', ''), ',', '')
like image 25
juergen d Avatar answered Mar 03 '23 01:03

juergen d