Dua kueri untuk menambah/mengurangi nilai bidang tidak diperlukan:
mysql_query("UPDATE table SET field = field + 1 WHERE id = $number");
adalah kueri yang benar-benar valid seperti yang Anda lihat selanjutnya:
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)
Setelah itu diuji, apakah Anda yakin Anda masuk ke if (loggedin())
klausa?
Saya harus setuju dengan KM
, akan menyenangkan untuk melihat output dari echo $query1;
atau echo $query2;