[Tutorial] How to: SQLite
#18

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Thanks for the quick response!

Sorry I didn't explain well, basically I just want to add a record when a player registers with basic information such as the player name and IP. And also a Primary Key as the player's ID, so this can act as a 'registered players count' also.


So when the player registers, what do I format the query as and what keyword do I use?


Edit: Think I figured it out! "INSERT INTO" should create a new row?
Yes. If you use the editor to create your database structure (your fields, etc.), then you can create an 'ID' field and set that as the auto-incrementing primary key. Every time you use "INSERT INTO" for that table, it will add your new row and it will set the ID to +1 from the previous row's ID field.

You can then use a SELECT query to get the highest ID to retrieve the count by the method you want:
Код:
SELECT ID from players ORDER BY ID DESC LIMIT 1
Something like the code above should work.

Alternatively, you could just use the num_rows function which calculates how many rows there are in the table. If you rely on the "ID" field, deleted accounts won't be considered and will still add to the count.

For that, you can use something like this for your query:
Код:
SELECT COUNT(*) FROM players
with this function. You don't want to use * to select everything, since you're just selecting a count of how many users there are, selecting * selects everything in your table and would frankly be a waste of memory.
Reply


Messages In This Thread
How to: SQLite (basic tutorial) - by __ - 17.06.2011, 22:54
Re: How to: SQLite - by __ - 17.06.2011, 23:06
Re: How to: SQLite - by Lorenc_ - 18.06.2011, 02:52
Re: How to: SQLite - by cessil - 18.06.2011, 05:33
Re: How to: SQLite - by __ - 18.06.2011, 11:32
Re: How to: SQLite - by Lorenc_ - 18.06.2011, 11:42
Re: How to: SQLite - by __ - 18.06.2011, 11:50
Re: How to: SQLite - by __ - 16.07.2011, 20:14
Re: How to: SQLite - by Jonny5 - 25.04.2012, 16:53
Re: How to: SQLite - by __ - 25.04.2012, 16:56
Re: How to: SQLite - by System64 - 25.04.2012, 17:33
Re: How to: SQLite - by ReneG - 13.05.2012, 17:32
Re: How to: SQLite - by __ - 14.06.2012, 10:08
Re: How to: SQLite - by Rudy_ - 14.06.2012, 10:12
Re: How to: SQLite - by Calgon - 14.06.2012, 10:17
Re: How to: SQLite - by __ - 14.06.2012, 10:18
Re: How to: SQLite - by Kindred - 14.06.2012, 10:44
Re: How to: SQLite - by __ - 14.06.2012, 10:47
Re: How to: SQLite - by TheLazySloth - 15.06.2012, 00:22
Re: How to: SQLite - by ReneG - 15.06.2012, 01:24
Re: How to: SQLite - by __ - 15.06.2012, 07:16
Re: How to: SQLite - by ReneG - 15.06.2012, 07:21
Re: How to: SQLite - by ReneG - 15.06.2012, 07:44
Re: How to: SQLite - by TheLazySloth - 15.06.2012, 16:14
Re: How to: SQLite - by Jonny5 - 15.06.2012, 16:29
Re: How to: SQLite - by ReneG - 15.06.2012, 17:11
Re: How to: SQLite - by kingchandio - 17.06.2012, 10:22
Re: How to: SQLite - by Calgon - 17.06.2012, 16:56
Re: How to: SQLite - by kingchandio - 17.06.2012, 21:01
Re: How to: SQLite - by Calgon - 17.06.2012, 22:50
Re: How to: SQLite - by Dodo9655 - 24.06.2012, 09:48
Re: How to: SQLite - by Kreatyve - 12.10.2012, 17:33
Re: How to: SQLite - by Guest4390857394857 - 22.02.2014, 13:46

Forum Jump:


Users browsing this thread: 5 Guest(s)