23.11.2017, 23:11
Using SELECT COUNT(*) will count itself the number of rows that the table "players" contains and return it:
Also replace SELECT NULL with SELECT *
Between this two I'd personally use SELECT COUNT(*), instead of selecting everything from the table and then counting each row.
Yes, you can check if a record exists without actually displaying it. For example, if you want to know if a player called John_Cena exists in the database:
This will return 1 if the record exists.
Код:
new DBResult:result = db_query(db, "SELECT COUNT(*) FROM players"); new count = db_get_field_int(result); //I think you don't really need this since SELECT COUNT(*) already returns an int db_free_result(result);
Код:
new DBResult:result = db_query(db, "SELECT * FROM players"); //this gets every record of the table players new count = db_num_rows(result); //counts the number of rows as int db_free_result(result);
Quote:
And another question: what, if I only want to know if a record just exists?
![]() |
Код:
SELECT 1 FROM players WHERE name = 'John_Cena'