Jump to content

Best method for this?


joecooper

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/256990-best-method-for-this/
Share on other sites

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.