Insert new data:
INSERT INTO table (height) VALUES (xxx);
Delete the pair (1,2.0):
DELETE FROM table WHERE id=1;
OR... all together like this:
UPDATE table SET height=xxx WHERE id=1;
I think I'm confused or thinking about this in the wrong way. I basically just need to insert in new data but only hold up to 5 entries. like the picture I had. Every time you insert in new data the last one will be deleted, and so on. I just thought you'd want to not increment the ID's every time you did. I'm so new to this...
id = 1. So I'd always keep a history of 4 after the newly inserted data. And I'm not even sure what ID's are... or why I'd want to increment them or reset them... so this is who you're dealing with =D
Is it bad for the ID to increment really far? If so, I would think it would be wise to just keep it to ID 1 through 5. New data is inserted at 5. ID 1 data is delete, and everything shifts down ID's.
This is what I have so far:
` $rand = rand(1,10);
mysql_query("INSERT INTO wave_data (height) VALUES ($rand)");
mysql_query("DELETE FROM wave_data ORDER BY id ASC LIMIT 1"); `
UPDATE table SET height=xxx WHERE id=(SELECT id FROM table ORDER BY id DESC LIMIT 1). The Select... gets the last one, ie, the one with greatest ID number.
To give you the context of what I'm doing. I'm scraping wave height from a buoy in the ocean every hour from a cron job that I just wrote. Where only the latest 5 readings are kept. Now I'd like to read the latest height that was inserted in.
=)
but since the ID are incrementing, I don't know how to read the 5th row and display it. Does that make sense?
by the way, SELECT height FROM table ORDER BY id DESC LIMIT 1 came up as: "Resource id #3"
This query will return the height from the row with the biggest id.
The ID is not important, you just have to know that if the AUTOINCREMENT is set, new rows will have bigger ID. So this way you will always get the last one by this SELECT ... ORDER BY id DESC LIMIT 1