joecooper Posted February 13, 2012 Share Posted February 13, 2012 Ill try explain it as best i can. My script is for a traffic exhange system. I have 2 tables, one is users (ID, UID and CREDITS) The other is links(ID,UID, LINK) UID is the User's ID. My script currently chooses a random user from users, and then chooses a random link from links (from that user), and then forwards the person running the script to that link. The problem is, I need to limit the amount of times one user can visit a link to 3 times max. Im not sure how to go about this. Do i add another feild on "links", with a list of all the users IDs'? and then parse this to check if they are on it 3 times? Thanks Joe Quote Link to comment https://forums.phpfreaks.com/topic/256990-best-method-for-this/ Share on other sites More sharing options...
Zane Posted February 13, 2012 Share Posted February 13, 2012 You'll need yet another table, using the link ID as the key. So you'll have ID, LINKID, UID, viewCount just addon to viewCount when they click the link... and deauthorize if it's greater than 3 Quote Link to comment https://forums.phpfreaks.com/topic/256990-best-method-for-this/#findComment-1317423 Share on other sites More sharing options...
joecooper Posted February 13, 2012 Author Share Posted February 13, 2012 You'll need yet another table, using the link ID as the key. So you'll have ID, LINKID, UID, viewCount just addon to viewCount when they click the link... and deauthorize if it's greater than 3 Ah thats spot on! So my code will choose a random UID, Then choose random link, and then check if that link has been selected already 3 times, if it has, choose another. Only problem, is i can see this being a problem if there is loads of links, it may take a while with many querys to find one that is less than 3. plus, if they are all more than 3, then it would be stuck in a loop. Any method around this? Quote Link to comment https://forums.phpfreaks.com/topic/256990-best-method-for-this/#findComment-1317817 Share on other sites More sharing options...
Zane Posted February 13, 2012 Share Posted February 13, 2012 Only problem, is i can see this being a problem if there is loads of links, it may take a while with many querys to find one that is less than 3. plus, if they are all more than 3, then it would be stuck in a loop. Any method around this? Talk to fenway, this could easily be alleviated with a few JOINs... at least I believe Quote Link to comment https://forums.phpfreaks.com/topic/256990-best-method-for-this/#findComment-1317904 Share on other sites More sharing options...
fenway Posted February 20, 2012 Share Posted February 20, 2012 Didn't this get answered already/ Quote Link to comment https://forums.phpfreaks.com/topic/256990-best-method-for-this/#findComment-1319183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.