Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Mysql query questions
Old 05-31-2008, 07:36 PM Mysql query questions
Junior Talker

Posts: 2
Trades: 0
Hi,

I have two tables:
users and active

The active table contains 3 fields:
ID, UID, TIME

users table contains:
ID, user, AC

example:
users:
1 xxx 0
2 xxa 3
3 asdas 5
4 sdss 1

active:
1 1 55545412
2 1 45454154
3 1 45541212
4 2 54541245
5 2 54541541



i need to increase the AC by 1, if (UNIX_TIMESTAMP()-active.TIME)<3600, and only once for each uid.

The system i've been using is somewhere like:


Quote:
$r=mysql_query("SELECT DISTINCT uid FROM active WHERE (UNIX_TIMESTAMP()-active.TIME)<3600");
while($x=mysql_fetch_array($r)){ mysql_query("Update users SET ac=ac+1 WHERE id=$x[uid]");}
But i want to use only one query, for performance reasons...
Something like:

Quote:
Update users SET ac=ac+1 WHERE (UNIX_TIMESTAMP()-active.TIME)<3600 AND users.id=active.uid
but with DISTINCT uid into the active table.
Can anyone help?


Thanks
cobracrk is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-09-2008, 07:04 AM Re: Mysql query questions
Average Talker

Posts: 18
Name: Phil
Location: Scotland
Trades: 0
I don't really see why you need two tables, I would just put a "lastactive" field in users and query that. Presuming you need it for the likes of "users logged on now" and such.
Bozebo is offline
Reply With Quote
View Public Profile Visit Bozebo's homepage!
 
Reply     « Reply to Mysql query questions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16519 seconds with 12 queries