Hello,
I add rows to the table using this command:
$timestamp = time() + ($delay*$i);
$sqlRequest = "INSERT INTO twitter(timestamp, user, pass, tweet) VALUES('$timestamp', '$user', '$pass', '$tweet')"
;
Now what I want to do is, check the database for entries that have timestamp lower than current time().
I want to extract data from these rows one by one and delete each afterwards.
Any ideas what mysql query I should use to achieve this?
r937
May 2, 2010, 8:57pm
2
extracting and deleting must be done in separate statements
i’m a little concerned about the “one by one” business, though
SELECT timestamp, user, pass, tweet
FROM twitter
ORDER BY timestamp DESC LIMIT 1
DELETE
FROM twitter
ORDER BY timestamp DESC LIMIT 1
Ok, so you ordered results for me by age, but how do I only fetch results that have timestamp older than current time?
r937
May 2, 2010, 9:02pm
4
omg i can’t believe i forgot that part!!
SELECT timestamp, user, pass, tweet
FROM twitter
WHERE timestamp < CURRENT_TIMESTAMP
ORDER BY timestamp DESC LIMIT 1
yeah, I am new to web stuff and I know nothing about mysql yet, so its very hard for me right now.
Let me try to put this into my little script.
I did run a query trough phpmyadmin and it worked
Ok, I got it working perfectly now, just had to remove DESC LIMIT 1 so it shows all results which I than filter and use one by one using for loop.
r937
May 2, 2010, 11:04pm
8
may i ask what you are doing with each row in your for loop?
I extract data from row, than post tweet on Twitter.com that is scheduled for that time.
I use Cron to run script every 60 seconds, so tweets scheduled for that minute are posted, and deleted from database.