This topic is locked
[SOLVED]

 Adding A Field to the view that adds total from a different table

2/27/2016 9:16:48 AM
PHPRunner General questions
M
mhollibush author

I am new at all of this so this question may not be worded right.
I have two tables ( Results and Person )
I want to add a field to the View Page on the Person that will add all the points in the "points column" in the Results Table and show total number of points earned based on the PersonId
Can anyone give me some pointers as to how to make this work
Any help would be greatly appreciated

M
mhollibush author 3/2/2016



I am new at all of this so this question may not be worded right.
I have two tables ( Results and Person )
I want to add a field to the View Page on the Person that will add all the points in the "points column" in the Results Table and show total number of points earned based on the PersonId
Can anyone give me some pointers as to how to make this work
Any help would be greatly appreciated


I want to use the code snippet on the list and view pages.

I need to write the sql query in the snippet, but I am not sure of the proper format to be used.
SELECT sum(points) FROM results WHERE playerId = ???
Can someone please point me in the right direction - Need to display the total points per playerId in the list page, and also the total points based on the current record of the view page ( playerId ) in the view page.
can someone show me a sample code of a snippet for this?
Thanks In Advance
I think its very basic, but I have no clue on how to get it in the code snippet -

jadachDevClub member 3/2/2016

Why not just create a view in your database that sums the values per playerId? Then in the SQL editor join your table to that new view using playerId as the fk. On the view page you can then show the total.

M
mhollibush author 3/2/2016



Why not just create a view in your database that sums the values per playerId? Then in the SQL editor join your table to that new view using playerId as the fk. On the view page you can then show the total.


I am trying to figure all this out - I am very new to this and I am confused on how to add the query to the current query that was created by default - I thought maybe putting a snippet in would do the trick.... open for suggestions
by default the table query grabs all the columns
the query I need to add to the existing

(SELECT SUM(points) FROM results where playerId = results.playerId) as points FROM results

M
mhollibush author 3/2/2016

With the help of the Admin, I was able to get part of it working.
Now I have a new issue where the query is causing the list view to display the same person 11 times - the numbers ( SUM ) are correct, but not sure why its listing each person multiple times