june_c21 Posted December 15, 2010 Share Posted December 15, 2010 hi , i want to select qty from master where id=$id , then i want to minus the qty = qty -1 and update in the query . here is my code . can tell me what went wrong ? $query= "SELECT qty FROM master where id=$id"; $result = mysql_query($query,$dblink); while($myrow = mysql_fetch_row($result)) { qty -= 1; $query = "UPDATE master SET qty='$qty' WHERE id= $id"; $result = mysql_query($query,$dblink); } thanks Quote Link to comment https://forums.phpfreaks.com/topic/221751-minus-1/ Share on other sites More sharing options...
MMDE Posted December 15, 2010 Share Posted December 15, 2010 $qnt=-1; mysql_query('UPDATE master SET qty=qty+'.$qnt.' WHERE id='.$id) or die(mysql_error()); or if you only want to minus 1 mysql_query('UPDATE master SET qty=qty-1 WHERE id='.$id) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/221751-minus-1/#findComment-1147625 Share on other sites More sharing options...
PFMaBiSmAd Posted December 15, 2010 Share Posted December 15, 2010 You only need these two lines of code - $query = "UPDATE master SET qty=qty - 1 WHERE id= $id"; $result = mysql_query($query,$dblink); Quote Link to comment https://forums.phpfreaks.com/topic/221751-minus-1/#findComment-1147626 Share on other sites More sharing options...
june_c21 Posted December 15, 2010 Author Share Posted December 15, 2010 thanks Quote Link to comment https://forums.phpfreaks.com/topic/221751-minus-1/#findComment-1147629 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.