mathieumg
3-27-05, 09:01 PM
Ok I have two tables:
members
id - int(15)
link - varchar(8)
credits - int(15)
given - int(15)
vacation - tinyint(1)
account_state - tinyint(1)
and
clicks
id - int(15)
click_time - int(15)
by_id - int(15)
for_id - int(15)
ip_addr - varchar(70)
This is a link trading site (each member's link is contained in link field of the members table)
What I want the query to do is list everybody (with their id) you can click.
Rules
-You cannot click the same link two times in 24 hours with the same IP
That means you can click someone 2 times or more in the same 24 hours if your IP changes, or you can wait 24 hours for the link to re-appear in the list if your IP don't changes.
-User must have credits (credits > 0)
-User's account must be active (account_state = 2)
-User must not be on vacation mode (vacation = 0)
Each time a click is done, a log entry is put in the clicks table,
click_time : Timestamp when the click was done
by_id : User who did the click's id
for_id : User who was clicked's id
ip_addr : User who did the click's IP
It must also works if the user was not clicked yet, because he just registered.
Here is my query with few PHP lines before it, I think I'm on a good way but I'm missing something, because it isn't working
//Query to get clickable users
$click_time=time()-86400;
$click_ip=$_SERVER["REMOTE_ADDR"];
$clicklist=new mysql();
$clicklist->query("SELECT members.id FROM members LEFT JOIN clicks ON clicks.for_id=members.id WHERE credits>'0' AND account_state='2' AND vacation='0' AND (clicks.click_time<'".$click_time."' OR clicks.click_time IS NULL) AND (clicks.ip_addr='".$click_ip."' OR clicks.ip_addr IS NULL) ORDER BY members.credits DESC, members.given DESC");
members
id - int(15)
link - varchar(8)
credits - int(15)
given - int(15)
vacation - tinyint(1)
account_state - tinyint(1)
and
clicks
id - int(15)
click_time - int(15)
by_id - int(15)
for_id - int(15)
ip_addr - varchar(70)
This is a link trading site (each member's link is contained in link field of the members table)
What I want the query to do is list everybody (with their id) you can click.
Rules
-You cannot click the same link two times in 24 hours with the same IP
That means you can click someone 2 times or more in the same 24 hours if your IP changes, or you can wait 24 hours for the link to re-appear in the list if your IP don't changes.
-User must have credits (credits > 0)
-User's account must be active (account_state = 2)
-User must not be on vacation mode (vacation = 0)
Each time a click is done, a log entry is put in the clicks table,
click_time : Timestamp when the click was done
by_id : User who did the click's id
for_id : User who was clicked's id
ip_addr : User who did the click's IP
It must also works if the user was not clicked yet, because he just registered.
Here is my query with few PHP lines before it, I think I'm on a good way but I'm missing something, because it isn't working
//Query to get clickable users
$click_time=time()-86400;
$click_ip=$_SERVER["REMOTE_ADDR"];
$clicklist=new mysql();
$clicklist->query("SELECT members.id FROM members LEFT JOIN clicks ON clicks.for_id=members.id WHERE credits>'0' AND account_state='2' AND vacation='0' AND (clicks.click_time<'".$click_time."' OR clicks.click_time IS NULL) AND (clicks.ip_addr='".$click_ip."' OR clicks.ip_addr IS NULL) ORDER BY members.credits DESC, members.given DESC");