Re: [PHP] Last visitors (SOLVED?)
Hey! I think I solved this: select 11 latest visitors count to see if it returned 11 records, if (count == 11){ get the oldest (of the 11) visitors time delete everything from that record and older than that } else{} Pros: max 2 queries If i am missing anything or you see any problem in my logic, please point it out. Thanks, Ryan -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.9.16 - Release Date: 4/18/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Last visitors (SOLVED?)
On Tuesday 19 April 2005 17:03, Ryan A wrote: Hey! I think I solved this: select 11 latest visitors count to see if it returned 11 records, if (count == 11){ get the oldest (of the 11) visitors time delete everything from that record and older than that } else{} Pros: max 2 queries Cons: 0. there are 3 queries: select, insert/update, delete 1. you're using more than 1 query 2. your logic is tough ;-) 3. you've mixed the php and mysql logic together. Check my reply. If i am missing anything or you see any problem in my logic, please point it out. Thanks, Ryan -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.9.16 - Release Date: 4/18/2005 -- Cyberly yours, Petar Nedyalkov Devoted Orbitel Fan :-) PGP ID: 7AE45436 PGP Public Key: http://bu.orbitel.bg/pgp/bu.asc PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436 pgp3WRVppS0aV.pgp Description: PGP signature
Re: [PHP] Last visitors (SOLVED?)
just do a select limit 11 display up to 11... if less then 11, you might want to display them anyways. you should be able to deal with up to a million + records, so select will stay quick, esp if you make the right fields indexed. you can take care of purging via crons... you might find you want the history in the end... -m Ryan A wrote: Hey! I think I solved this: select 11 latest visitors count to see if it returned 11 records, if (count == 11){ get the oldest (of the 11) visitors time delete everything from that record and older than that } else{} Pros: max 2 queries If i am missing anything or you see any problem in my logic, please point it out. Thanks, Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Last visitors (SOLVED?)
Hey, Thanks for replying. Check my reply. I did, the problem is the client is on a box with mySql 3.23.x or 4.0.x, he is deciding to upgrade to a dedicated box but then the host he is looking at says they will charge him if they are to upgrade to mysql 4.1 (hence i cant even use sub-selects) (Sorry I didnt mention the MySql version before...didnt think it was important till now) Cons: 0. there are 3 queries: select, insert/update, delete True 1. you're using more than 1 query Giving the fact that i am on a low version of MySqlI dont see much choice here 2. your logic is tough ;-) Thats pretty cryptic...care to explain please? 3. you've mixed the php and mysql logic together. again...what other choices do i have given the low version of MySql Cheers, Ryan -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.9.16 - Release Date: 4/18/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Last visitors (SOLVED?)
I did, the problem is the client is on a box with mySql 3.23.x or 4.0.x, he is deciding to upgrade to a dedicated box but then the host he is looking at says they will charge him if they are to upgrade to mysql 4.1 (hence i cant even use sub-selects) (Sorry I didnt mention the MySql version before...didnt think it was important till now) The MySQL version should not matter for what he was saying (you don't need subqueries). I think he was saying that every time you insert a user, also insert 10 records into the users profile_viewed_log. with an empty timestamp. Then, every time someone views the profile, update the profile_viewed_log, instead of inserting into it. (which can be done with a simple query...) $SQL = UPDATE profile_log SET user_id=.$userId., date_entered='1113931530' WHERE profile_id=. $profileId. ORDER BY date_entered ASC LIMIT 1; (the date i have is a unix timestamp, but you can use whatever format you wish). I havn't tested that query, but it should work with no problem. Basically, it just updates the first record with the smallest timestamp. Then, when you want to show the user the views for his/her profile, you just exclude the one's with an empty timestamp. Your other option, which also would work well, would be to do the cron job, with a limit value on the query. IMHO this is better than 3 queries every time someone views a profile. Also, you can set the cron job to run at 3AM, when there are not likely to be many users. Hope this helps some. -Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php