Raised This Month: $ Target: $400
 0% 

SQL max 20 lines


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 01-05-2011 , 15:36   SQL max 20 lines
Reply With Quote #1

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
reinert is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-06-2011 , 02:11   Re: SQL max 20 lines
Reply With Quote #2

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;" 
__________________
Impossible is Nothing
Sylwester is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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