Jump to content

Recommended Posts

I have a table like this:

 

primary-id / user-id / payment / charge

 

The 'payment' and 'charge' fields are decimal (5,2) datatypes and refer to a payment into the account and charge on the account.

 

So, for user 1, these records may exist:

 

1 / 1 / 20.00 /

93 / 1 / 10.00 /

159 / 1 / / 5.00

 

… so their account balance would be $25

 

Imagine the user's table as simply being Name / id / is_active

 

Dave / 1 / 1 (example above)

Jim / 2 / 0 (an inactive user)

 

I need to return any user where their account balance is more than $2 in the red.

 

I imagine it would be something like this:

 

SELECT user-details, actual-a/c-balance WHERE SUM(etc.)<-2

 

…but could do with a bit of help. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/243607-simple-php-mysql-query/
Share on other sites

Thanks for this, except I forgot one important thing (sorry):

 

The two tables are actually in different databases. They are on the same db server, but use a different user id / password to access them. I have all the usernames/passwords. Is this possible?

 

If not, what do I do as moving them isn't possible? Would I need to dump the entire accounts table and do a sort in PHP?

.... Would I need to dump the entire accounts table and do a sort in PHP?

 

Surely dumping the users table would be much quicker and easier to work with?

But, yeah, as fenway said - can't you just make a login with read access to both databases?  It's definately the option that makes most sense.

Can't create a single login due to limitations of hosting provider. Each db must have a separate user login.

 

In the end the obvious thing is to use kickstart's query (but for the accounts table only) and as not too many records would be returned (I'm only looking to return accounts in the red), I can then run another query (on the 'users' db) to get the user name and any other info using whatever id's are returned from the search of the accounts db. A lot of the time there won't be anything returned at all from the 'accounts' db anyway, so no further query needed.

 

I've done this and it works great.

 

Thanks for all the help.

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.