oracle765 Posted January 7, 2014 Share Posted January 7, 2014 Hi Professionals I have problems with my code and I cannot figure out why it is not updating the price by 1 Within the database the merchant table price is decimal 10.2 and the name is varchar thanks config.php masters.php Link to comment https://forums.phpfreaks.com/topic/285160-my-price-does-not-seem-to-be-updating/ Share on other sites More sharing options...
gristoi Posted January 7, 2014 Share Posted January 7, 2014 <? include_once('includes/config.php'); $increment = 1; //get values of each member $query="SELECT `name`, `price` FROM merchant"; $result=mysql_query($query); $num=mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { $value = (float)$row['price] + (float)$increment; $query2 = "UPDATE merchant SET `price`='$value' WHERE `name`='Harvey Norman' and price ='141.00'"; $result2 = mysql_query($query2); } // close connection mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/285160-my-price-does-not-seem-to-be-updating/#findComment-1464232 Share on other sites More sharing options...
Barand Posted January 7, 2014 Share Posted January 7, 2014 if you have 1000 records in that table then you run that update 1000 times. All you need is $query2 = "UPDATE merchant SET price= price+$increment WHERE `name`='Harvey Norman' and price = 141.00 "; $result2 = mysql_query($query2); Link to comment https://forums.phpfreaks.com/topic/285160-my-price-does-not-seem-to-be-updating/#findComment-1464233 Share on other sites More sharing options...
oracle765 Posted January 7, 2014 Author Share Posted January 7, 2014 ive tried that and my dreamweaver php editor shows and error for the last 2 lines of code you provided $query2,$result2 Link to comment https://forums.phpfreaks.com/topic/285160-my-price-does-not-seem-to-be-updating/#findComment-1464242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.