AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQL max 20 lines (https://forums.alliedmods.net/showthread.php?t=147125)

reinert 01-05-2011 15:36

SQL max 20 lines
 
Hey, how to make a sql, I want to add a line each time when map changes,

But I want to make max 20 lines in sql, so that the last lines disappear...

For example, I've 20 lines

1. aa
2. bb
...
...
18. cc
19. dd
20. ee

When 1 line adds the 19 (was dd now cc) line became 20 (was ee now dd) and 20 (which one was ee) disappears...

I hope u understood me because I don't know how to explain it ;D

Sylwester 01-06-2011 02:11

Re: SQL max 20 lines
 
Create your table with auto_increment primary key
PHP Code:

"CREATE TABLE IF NOT EXISTS table_name ( id INT(11) NOT NULL AUTO_INCREMENT, content VARCHAR(32), PRIMARY KEY ( id ) );" 

Use this to insert into your table:
PHP Code:

"INSERT INTO table_name (content) VALUES ('%s'); DELETE FROM table_name WHERE id<(SELECT id FROM table_name ORDER BY -id LIMIT 1)-19;" 



All times are GMT -4. The time now is 02:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.