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
https://forums.phpfreaks.com/topic/28170-read-from-2-tables-solved/
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'
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?
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
[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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.