I hope this isn't a duplicate post. I was working on a reply and got distracted. I can't find my draft or completed post so here goes again.
I have a table of taverns, players at those taverns and of points for each player. I need to total the points for each player then print out a list of all the players at one tavern with their point totals and arrange them by their total points.
I decided to find the tavern first. Accomplished.
Then find a list of the players of that tavern. Accomplished.
Then total the points for that player and store it to a variable. Stuck.
I am attempting to step through the list of players with a while statement,
adding up the point totals for a single player. Later I will need to output a list of players and their points, arranged by point totals.
The fields in the Points table are : id, player_id, tavern_id,date,tnumber,finished,points. 6 of the fields are integers but I only want to total the [points]. The sum_array function would probably look something like
Code: Select all
array_sum ($player_points[points])
.
The first obstacle I ran into with the sum_array approach was an error returned by my get_points_by_id function for the players who had no points. The RETURN value from the function is NULL for players with no points. The sum_array function is expecting an array and there is no array for players with no points. I am working on building an array with a points value of 0 and returning that instead of NULL. I THINK that will work but am not sure.
Another approach is to have an if(!NULL) condition to deal with the players with no points.