Pulling rows from two tables in the same database...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
orbdrums
Forum Commoner
Posts: 82
Joined: Wed Sep 14, 2011 11:42 pm

Pulling rows from two tables in the same database...

Post by orbdrums »

I can't seem to get a query to work properly. What I'm trying to do seems simple enough but not simple enough for me I guess. I want to pull fields (login_date, login_time) from a table called login_hist. I also want to pull fields (logout_date, logout_time) from a table called logout_hist WHERE a common field in both tables (member_id) equals the currently logged in member. Here is the code that is returning the query error:

Code: Select all

Invalid query: Column 'member_id' in where clause is ambiguous Whole query: SELECT * FROM login_hist,logout_hist WHERE member_id = 4 ORDER BY `login_date` DESC, `login_time` DESC
And here is the error:

Invalid query: Column 'member_id' in where clause is ambiguous Whole query: SELECT * FROM login_hist,logout_hist WHERE member_id = 4 ORDER BY `login_date` DESC, `login_time` DESC

Any help would be greatly appreciated.
C
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Pulling rows from two tables in the same database...

Post by mikosiko »

Do not duplicate your posts... a clear answer was already given to you here
http://www.devnetwork.net/viewtopic.php ... e742337fb2
orbdrums
Forum Commoner
Posts: 82
Joined: Wed Sep 14, 2011 11:42 pm

Re: Pulling rows from two tables in the same database...

Post by orbdrums »

I wouldn't duplicate posts if they weren't moved. Someone moved my post and I couldn't find it so I posted it again. If another one of my posts is moved I will repost another one. Simple as that.
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: Pulling rows from two tables in the same database...

Post by mikeashfield »

orbdrums wrote:I wouldn't duplicate posts if they weren't moved. Someone moved my post and I couldn't find it so I posted it again. If another one of my posts is moved I will repost another one. Simple as that.

Your posts (for future reference).
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Pulling rows from two tables in the same database...

Post by pickle »

Locking thread.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Locked