Twee zoekopdrachten om de veldwaarde te verhogen/verlagen zijn niet nodig:
mysql_query("UPDATE table SET field = field + 1 WHERE id = $number");
is een perfect geldige zoekopdracht, zoals u hierna kunt zien:
mysql> describe points;
+--------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------+------+-----+---------+-------+
| uid | int(11) | NO | PRI | NULL | |
| points | int(11) | YES | | 0 | |
+--------+---------+------+-----+---------+-------+
2 rows in set (0.05 sec)
mysql> insert into points VALUES (1,0),(2,0);
Query OK, 2 rows affected (0.14 sec)
mysql> select * from points;
+-----+--------+
| uid | points |
+-----+--------+
| 1 | 0 |
| 2 | 0 |
+-----+--------+
2 rows in set (0.05 sec)
mysql> update points set points = points+1 where uid = 1;
Query OK, 1 row affected (0.27 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from points;
+-----+--------+
| uid | points |
+-----+--------+
| 1 | 1 |
| 2 | 0 |
+-----+--------+
2 rows in set (0.00 sec)
Na dat te hebben getest, weet u zeker dat u in uw if (loggedin())
. komt clausule?
Ik moet akkoord gaan met KM
, zou leuk zijn om de uitvoer van echo $query1;
. te zien of echo $query2;