Jump to content

Remove $ sign from all fields in database column


sh0wtym3

Recommended Posts

Hey all,

 

I have a database column named "price", and all the fields there have numbers that start with a '$'... because of this I can't do mathematical calculations with those numbers.

 

Is there a way to loop through the rows and remove the '$' sign from the front of each number?

 

I've figured it out, I was using the wrong syntax. For anyone with a similar problem here is the solution:

 

$sql = "SELECT * FROM table";
$res = mysql_query($sql, $conn);
while ($row = mysql_fetch_array($res)) {
$id = $row['id'];
$price = $row['price'];
$newprice = str_replace("$", "", $price);
$sql2 = "UPDATE table SET price = '$newprice' WHERE id = '$id'";
$res2 = mysql_query($sql2, $conn);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.