Forum Moderators: coopster

Message Too Old, No Replies

PHP queries across Databases

         

dave1236

7:23 pm on Jan 15, 2007 (gmt 0)

10+ Year Member



This is a follow-up to my previous post...thnaks to Masterscripdel for putting me on the right track!

I have been asked to provide the ability for admins to see when a user logs into my site. In short, I have a login for all members of a certain group. The admin of this group would like the ability to see when and how many people login.

I have two tables that are relevant.

1) Login (fields loginName, date)
2) Member (fields accountName and loginName)

As further detail, here is an example:

GroupA has the following attributes:

In login, loginName = GroupA
In Member, loginName= GroupA and accountName is blank.

AdminGroupA has the following:

In login, loginName = AdminGroupA
In Member, loginName = AdminGroupA and accountName = GroupA

I am trying to write a query that will accomplish the following:

When AdminGroupA logs in, they will have a report that accomplishes the following:

$sql = "SELECT * FROM Login WHERE Login.loginName = Member.accountName" for all instances where GroupA has logged in. (this query, as written, returns all my logins, regardless of permissions. It shows all logins for all admins settings.)

How do I select only those logins where:

Member.loginName = AdminGroupA and Login.loginName = Member.accountName?

I have tried the following, but it does not execute:

$sql = "SELECT * FROM Login
WHERE loginName=Member.accountName AND Member.loginName='{$_SESSION['logname']}'";

Thanks again!

mcibor

8:11 am on Jan 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try the following:

$sql = "SELECT Login.* FROM Login, Member
WHERE Login.loginName=Member.accountName AND Member.loginName='{$_SESSION['logname']}'";

Hope this helps

Michal

dave1236

3:52 pm on Jan 16, 2007 (gmt 0)

10+ Year Member



Thanks!

That works...funny how I was missing one thing! Certainly appreciate your help!

Thanks again!