phpnewbie88 Posted October 22, 2010 Share Posted October 22, 2010 Hello, I am trying to use the php function string substr ( string $string , int $start [, int $length ] ) to remove trailing zero's in the DB from the price displayed on the page. Currently using the code below I get this for output - $27.9500 <?php echo $row['prodprice']; ?> I would like to get this $27.95. So I tried using the string substr ( string $string , int $start [, int $length ] ) like this - <?php echo substr("$row['prodprice']",0,5); ?> but I receive t string errors and such using variations of this. Can someone please explain to me what I am doing wrong and give me some pointers on how to fix this? Thanks Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 22, 2010 Share Posted October 22, 2010 If it's is stored as a decimal value in the database (it really should be), you can use ROUND() in the query SELECT ROUND(`prodprice`, 2) AS price FROM `table` The value would then be in $row['price'] Quote Link to comment Share on other sites More sharing options...
phpnewbie88 Posted October 22, 2010 Author Share Posted October 22, 2010 $result = mysql_query("SELECT * FROM isc_products,isc_product_images WHERE productid='537'") or die(mysql_error()); right now i am using this, how would I implement your code suggestion? If it's is stored as a decimal value in the database (it really should be), you can use ROUND() in the query SELECT ROUND(`prodprice`, 2) AS price FROM `table` The value would then be in $row['price'] Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 22, 2010 Share Posted October 22, 2010 This should work for you. Then you'd just need to change your echos to reflect $row['price'] instead of $row['prodprice'], and get rid of all the substr() usage. SELECT *, ROUND(`prodprice`, 2) AS price FROM isc_products,isc_product_images WHERE productid='537' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.