I'm thinking that this query can be done on the database side rather than using php and looping and doing thousands of queries. What I'm wanting to do is this:
INSERT INTO `table` (`username`, `activity`) VALUES(SELECT `username`, `activity` FROM `users);
What I would like for that to do is insert a record with username and activity fields for each user in the users table. I would also like to pass the current timestamp (time()) into a third field, but I figured that may not be possible doing that type of query.
Obviously the above query doesn't work.. any help?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
That is super sweet, thanks man. I've been doing so much work at the PHP level, I've decided to transfer as much work to the database as I can and take advantage of database syntax and functions... will save me lots of php code.
Using that above query (which worked flawlessly, and fast!).. is there a way to insert the current time() as a third parameter..
INSERT INTO `table` (`username`, `activity`, `time`) SELECT `username`, `activity` FROM `users`, NOW();
Dang, I feel like a newbie at this. That mysql manual sure is a bit hard to understand.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Setting the `time` field with DEFAULT CURRENT_TIMESTAMP solved the problem. (guess I can read the manual after all ). It doesn't save in timestamps, but it will work for me.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
INSERT INTO credits_history (
`username`,
`credits`,
`views`)
SELECT
`username` AS `uname`,
`credits_today`,
(SELECT
SUM(`credits_used_today`)
FROM
`sites`
WHERE
`username` = `uname`)
FROM users;
Seems simple, but took me a while to write it.
The only problem I have with the above query is that sometimes count(*) returns null instead of 0.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.