ballouta Posted June 16, 2008 Share Posted June 16, 2008 hi I have the table credits: user creditsnum ============= me 500 Am I able to make a query that decreases creditsnum (-1) according to a selected user I already have? thanks Link to comment https://forums.phpfreaks.com/topic/110479-solved-decreasing-a-value-using-select-query/ Share on other sites More sharing options...
themistral Posted June 16, 2008 Share Posted June 16, 2008 Try using an update query that sets creditsnum = creditsnum-1 It might be a bit simplistic - give it a go and let us know how you get on! Link to comment https://forums.phpfreaks.com/topic/110479-solved-decreasing-a-value-using-select-query/#findComment-566809 Share on other sites More sharing options...
ballouta Posted June 16, 2008 Author Share Posted June 16, 2008 I tried these but not working $query = " UPDATE `gsclteam_gsteam`.`credits` SET `creditsnum` = creditsnum-1 WHERE `uploaded`.`user` = '$user' "; $query = " UPDATE `gsclteam_gsteam`.`credits` SET `creditsnum` = 'creditsnum-1' WHERE `uploaded`.`user` = '$user' "; Why? Link to comment https://forums.phpfreaks.com/topic/110479-solved-decreasing-a-value-using-select-query/#findComment-566817 Share on other sites More sharing options...
hitman6003 Posted June 16, 2008 Share Posted June 16, 2008 you are using two different tables...one to update, and another in the WHERE clause, but not identifying how to join them together. Perhaps you should start there. Link to comment https://forums.phpfreaks.com/topic/110479-solved-decreasing-a-value-using-select-query/#findComment-566825 Share on other sites More sharing options...
ballouta Posted June 16, 2008 Author Share Posted June 16, 2008 sorry, yes there's a mistake in the query, actually i need to use only one table the code is fixed now: $query = " UPDATE `credits` SET `creditsnum` = creditsnum-1 WHERE `user` = '$user' "; $result = mysql_query($query); still not working, is there another way to make creditsum = creditsnum -1 ? Link to comment https://forums.phpfreaks.com/topic/110479-solved-decreasing-a-value-using-select-query/#findComment-566828 Share on other sites More sharing options...
ballouta Posted June 16, 2008 Author Share Posted June 16, 2008 sorry I had a problem with the $user, I fixed it and the query is working many thanks Link to comment https://forums.phpfreaks.com/topic/110479-solved-decreasing-a-value-using-select-query/#findComment-566834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.