SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Dec 17, 2009, 09:25 #1
MYSQL On Duplicate (Exclusion Clause?)
PHP Code:$update = '('.$site_id.',"'.$user_id.'","'.$online_ip.'",'.$time.')';
$sql_online = 'INSERT INTO `user_online` (site_id, user_id, online_ip, online_timestamp) VALUES '.$update.' ON DUPLICATE KEY UPDATE online_timestamp=VALUES(online_timestamp)';
online_ip - Primary Key
site_id - Unique Key
user_id
online_timestamp
As you can see the above works well as a Users Currently Online, as every time the user visits a page it inserts their information, or updates the timestamp.
The problem I have is that two websites useing same database, with the difference site_id value.
Ive noticed that If i go to Site 1, then Site 2. Only Site 1 is visitor is counted.
Is their a way around this obstacle, a conditional clause on site_id ?
-
Dec 17, 2009, 09:34 #2
Make your primary key: online_ip, site_id
Guido - Community Team Leader
The Votes Are In: The Winners of the 2013 Community Awards are...
Blog - Free Flash Slideshow Widget
-
Dec 20, 2009, 09:48 #3
That seems to do the trick, thanks for your time!
It passed my mind that you could have two primary keys.
-
Dec 20, 2009, 13:55 #4
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
strictly speaking, no, you can't have two primary keys
you can have only one primary key, but it can be a composite key consisting of more than one column
Bookmarks