sh0wtym3 Posted March 12, 2010 Share Posted March 12, 2010 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? Link to comment https://forums.phpfreaks.com/topic/195043-remove-sign-from-all-fields-in-database-column/ Share on other sites More sharing options...
sh0wtym3 Posted March 12, 2010 Author Share Posted March 12, 2010 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); } Link to comment https://forums.phpfreaks.com/topic/195043-remove-sign-from-all-fields-in-database-column/#findComment-1025309 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.