SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot NuWeb's Avatar
    Join Date
    Aug 2005
    Location
    UK
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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)'
    Table: user_online
    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 ?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Make your primary key: online_ip, site_id

  3. #3
    SitePoint Zealot NuWeb's Avatar
    Join Date
    Aug 2005
    Location
    UK
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That seems to do the trick, thanks for your time!

    It passed my mind that you could have two primary keys.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •