MySQL query problem - Looped results

Discussion in 'MySQL' started by sandstorm140, Mar 4, 2009.

  1. #1
    Hello,
    I'm using the following code. I'm wanting to display usernames from
    database: usernames
    table: users
    from field: online
    where online = 1.

    As you can see, i also have FROM accounts.accounts because later on I will need to pull information from that database simultaneously.
    Database: accounts
    table: accounts
    --Also has a field named "online".

    My problem is I should have 4 results equal to usernames.users.online=1.
    I get the correct 4 names, however, it seems to be looped over and over again hundreds of times.

    For example:
    username1
    username2
    username3
    username4
    //starts again..
    username1
    username2
    username3
    username4
    ...etc

    
    SELECT
    usernames.users.name, usernames.users.online
    FROM
    usernames.users,
    accounts.accounts
    WHERE
    usernames.users.online =  '1'
    
    Code (markup):
    I'm fairly new to MySQL, any help/advice would be splendid.

    Thanks in advance.
     
    sandstorm140, Mar 4, 2009 IP
  2. sandstorm140

    sandstorm140 Peon

    Messages:
    80
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Nevermind, got it figured out with JOIN
     
    sandstorm140, Mar 4, 2009 IP
  3. peterCx

    peterCx Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    SELECT
    usernames.users.name, usernames.users.online
    FROM
    usernames.users,
    accounts.accounts
    WHERE
    usernames.users.online = 1 // if online is numberic
     
    peterCx, Mar 9, 2009 IP