This topic is locked

subtracting childnumber from another field

5/7/2009 12:01:44 AM
PHPRunner General questions
W
wfcentral author

I have created a database to track everytime a member visits a club.
They are allows "x" number of visits per month or year.
So, I have a field called "visits allowed" in tbl_members
I have a child table called tbl_visits that is linked to tbl_members
I can add "visits" to a member and the tbl_visits_childnumber will show how many visits they have
Now, I just need to subtract tbl_visits_childnumber from tbl_members.visitsAllowed so I can generate "visitsRemaining"
Any ideas?

J
Jane 5/7/2009

Hi,
where do you want to calculate this value? Do you want to save this value in the database? Or do you want to check calculated value on the login page?

Please give me more detailed description of what you want to achieve.

W
wfcentral author 5/7/2009

Hi,

where do you want to calculate this value? Do you want to save this value in the database? Or do you want to check calculated value on the login page?

Please give me more detailed description of what you want to achieve.


on the list page for the tbl_members I want to show how many "visits" they have left on their account.
The number of visits left is calculated by subtracting number of entries in tbl_visits with their user_ID FROM the number of visits they are allowed to have (tblmembers.visitsAllowed).
I thought it would be simple since the number of visits they have used shows up by the child object link on the list page...
____name__visits allowed__visits remaining

visits(2)John Smith__33____31__

J
Jane 5/8/2009

Hi,
edit SQL query on the Edit SQL query tab for this purpose.

Here is a sample:

SELECT tbl_members.name, tbl_members.visitsAllowed-count(tbl_visits_childnumber.FieldName) as `visits remaining`

FROM tbl_members

INNER JOIN tbl_visits_childnumber ON tbl_members.linkfield1 = tbl_visits_childnumber.linkfield2

GROUP BY tbl_members.name

W
wfcentral author 5/8/2009

Hi,

edit SQL query on the Edit SQL query tab for this purpose.

Here is a sample:


I think what you are saying is that I need to go to the Query section (I'm using 5.1) and then to the SQL tab to edit my initial SQL call. I tried that and got an error that tbl_visits_childnumber does not exist...
here is the SQL call I'm using now...
SELECT

id,

password,

gym_ID,

firstname,

lastname,

address1,

address2,

city,

`state`,

zip,

home_phone,

mobile_phone,

status,

status_comment,

email,

contract_endDate,

`plan`,

gym_membership_id,

contract_startDate,

unlimited,

DATEDIFF(contract_endDate, now()) AS ContractDaysLeft,

DATEDIFF(contract_endDate, contract_startDate) AS ContractLength,

round((DATEDIFF(contract_endDate, contract_startDate)/30)*plan) AS visitAllowed

FROM tbl_members

ORDER BY lastname
by the way, I must say I am always impressed with the number of people you support and the answers you give...

J
Jane 5/11/2009

Hi,
this error means that table name is incorrect.

You can publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages and I'll try to help you.