cliftonbazaar Posted February 10, 2010 Share Posted February 10, 2010 At the moment I have lots of code that look like this $temp=$player['matchesPlayed']+1; $sqlPlayer .= " matchesPlayed='{$temp}', "; to increase a variable in the database by 1, as I have to increase a lot of variables is there a better way of writing this? I first tried $sqlPlayer .= " matchesPlayed='{$player['matchesPlayed']++}', but it didn't work Link to comment https://forums.phpfreaks.com/topic/191597-increasing-a-variable-by-one/ Share on other sites More sharing options...
jskywalker Posted February 10, 2010 Share Posted February 10, 2010 why did you use the '{}' in this: $sqlPlayer .= " matchesPlayed='{$player['matchesPlayed']++}', try: $sqlPlayer .= " matchesPlayed='".$player['matchesPlayed']++."'," Link to comment https://forums.phpfreaks.com/topic/191597-increasing-a-variable-by-one/#findComment-1009972 Share on other sites More sharing options...
trq Posted February 10, 2010 Share Posted February 10, 2010 why did you use the '{}' in this Because complex variables (eg; arrays) should be surrounded by braces when within strings. Anyway, you can simply update records and increase there value without having to execute a SELECT query first (which it appears you are doing) $sqlPlayer .= " matchesPlayed=matchesPlayed+1"; Link to comment https://forums.phpfreaks.com/topic/191597-increasing-a-variable-by-one/#findComment-1010015 Share on other sites More sharing options...
cliftonbazaar Posted February 11, 2010 Author Share Posted February 11, 2010 Thanks for that thorpe, worked an absolute treat and I knocked out about a third of the code in that section - works a lot faster now that I don't have to use a SELECT first as well Link to comment https://forums.phpfreaks.com/topic/191597-increasing-a-variable-by-one/#findComment-1010908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.