Jump to content

Read from 2 tables *SOLVED*


SkyRanger

Recommended Posts

I am trying to pull info from two tables. I am not very good at the join command.  I have tried everything I know with no luck which brings me here.  can somebody help.

This is what I need.
2 Tables:  client and addserv

I am trying to select * and display data from both client and addserv where username='Ausernamehere'
Link to comment
Share on other sites

Thanks, this is what I currently have:

[code]
$result = mysql_query( "SELECT * FROM client, addserve WHERE client.username = addserve.username AND username = '$username'") or die( "Unable to select database");
[/code]

What I want to do is:  pull out all the info from the client table plus all of the info from addserve where the username in both equals a clients username.  ie: username='$username'
Link to comment
Share on other sites

I keep getting: Unable to select database

When I select from 1 table no problems, when I try to get data from 2 tables, that is where I get lost.  That example that was provided I copied and pasted, but never worked.  I am a NOOB at php/mysql but i then changed it to client.username = addserve.username  which is probably not right.  Can anybody give me a hand here?
Link to comment
Share on other sites

Not sure what you would be looking for but sure:

Table: client

id: 1
name: John Smith
Username:  jsmith
password: a1b3#f
Address: 123 My Street

Table: addserve:
username: jsmith
serv:  Package 1


Display Would be:

Full Name:  John Smith
Username: jsmith
password: a1b3#f

Package Ordered:  Package 1
Link to comment
Share on other sites

[quote author=SkyRanger link=topic=115975.msg472610#msg472610 date=1164292362]
Thanks, this is what I currently have:

[code]
$result = mysql_query( "SELECT * FROM client, addserve WHERE client.username = addserve.username AND username = '$username'") or die( "Unable to select database");
[/code]

What I want to do is:  pull out all the info from the client table plus all of the info from addserve where the username in both equals a clients username.  ie: username='$username'
[/quote]

Try to put table_name.username
For example:
--------------------
$result = mysql_query( "SELECT * FROM client, addserve WHERE client.username = addserve.username AND [color=red]client.[/color]username = '$username'") or die( "Unable to select database");
--------------------
Because column 'username' in where clause is ambiguous
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.