Jump to content

increasing a variable by one


cliftonbazaar

Recommended Posts

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

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.