SkyRanger Posted November 22, 2006 Share Posted November 22, 2006 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 addservI 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 More sharing options...
impulse() Posted November 22, 2006 Share Posted November 22, 2006 Hello.Try:[code]SELECT *FROM client, addservWHERE somethingFromClient = somethingFromAddservAND username = '$username'[/code]Hope that helps, Link to comment https://forums.phpfreaks.com/topic/28170-read-from-2-tables-solved/#findComment-128861 Share on other sites More sharing options...
SkyRanger Posted November 23, 2006 Author Share Posted November 23, 2006 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 https://forums.phpfreaks.com/topic/28170-read-from-2-tables-solved/#findComment-129122 Share on other sites More sharing options...
SkyRanger Posted November 23, 2006 Author Share Posted November 23, 2006 I keep getting: Unable to select databaseWhen 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 https://forums.phpfreaks.com/topic/28170-read-from-2-tables-solved/#findComment-129183 Share on other sites More sharing options...
mansuang Posted November 23, 2006 Share Posted November 23, 2006 Could you show some example data in your database? Link to comment https://forums.phpfreaks.com/topic/28170-read-from-2-tables-solved/#findComment-129202 Share on other sites More sharing options...
SkyRanger Posted November 23, 2006 Author Share Posted November 23, 2006 Not sure what you would be looking for but sure:Table: clientid: 1name: John SmithUsername: jsmithpassword: a1b3#fAddress: 123 My StreetTable: addserve:username: jsmithserv: Package 1Display Would be:Full Name: John SmithUsername: jsmithpassword: a1b3#fPackage Ordered: Package 1 Link to comment https://forums.phpfreaks.com/topic/28170-read-from-2-tables-solved/#findComment-129233 Share on other sites More sharing options...
mansuang Posted November 23, 2006 Share Posted November 23, 2006 [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 https://forums.phpfreaks.com/topic/28170-read-from-2-tables-solved/#findComment-129247 Share on other sites More sharing options...
SkyRanger Posted November 23, 2006 Author Share Posted November 23, 2006 Awsome, got it to work, Thank you very much Link to comment https://forums.phpfreaks.com/topic/28170-read-from-2-tables-solved/#findComment-129261 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.