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 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()); 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); 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 Link to comment https://forums.phpfreaks.com/topic/221751-minus-1/#findComment-1147629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.