Help fetch data from another table ..

Discussion in 'PHP' started by DonWar, Oct 25, 2008.

  1. #1
    Ok ...

    I have a table named " users " which i am connected too.

    $fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'"));

    I have a table named " crews " which i need to get data from.

    What code i use to get be connected to both database table on one page?

    Daz.
     
    DonWar, Oct 25, 2008 IP
  2. IGiveMoney

    IGiveMoney Peon

    Messages:
    116
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Daz,

    You could do something like:

    
    
    $fetch=mysql_fetch_object(mysql_query("SELECT user.*, crew.* FROM users, crew WHERE users.username='$username' AND crew.name = '$crew_name'"));
    
    
    PHP:
    You can get specific based on that as well...

    example do something like

    $fetch=mysql_fetch_object(mysql_query("SELECT users.username, crew.name...
     
    IGiveMoney, Oct 25, 2008 IP
  3. DonWar

    DonWar Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    huh sow what is the propa connetion ?

    Thank you.
     
    DonWar, Oct 25, 2008 IP
  4. DonWar

    DonWar Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sow what is the real connection?

    Thank You.
     
    DonWar, Oct 25, 2008 IP
  5. IGiveMoney

    IGiveMoney Peon

    Messages:
    116
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    if users and crew are part of the same database (meaning under the same user and pass for your database connection) then what I showed you will work.

    If it isn't then you either need to move the crews table in with the users and use what i gave you
    or you need to setup a new connection to access the crews table within the other database.
     
    IGiveMoney, Oct 25, 2008 IP
  6. DonWar

    DonWar Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    not work becuase ..

    table = " users " not " user "
    table 2 = " crews " not " crew "

    I cant change the code becuase i dont no which needs changing?
     
    DonWar, Oct 25, 2008 IP
  7. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This forum is for helping you, but ultimately we all want you to learn stuff, and not do your work for you. Why don't you look into MySQL a little?
     
    Kyosys, Oct 26, 2008 IP