Hello all,
I currently have a a fabrik application that keeps track of games and team records. Right now, a teams win loss record is updated after a game score is submitted. So after the game form is submitted, it calculates the winner based on score and adds a win to the win column of the teams record:
The flaw with this is that it will perform every time the form is submitted. This will cause the form to perform an update on the win and loss column every time the forum is updated.
I think what I want to do is calculate the win and loss fields in my list view instead. I should create a winner_id and a loser_id element in my game list and the win loss field of each team should calculate how many times they appear in winners_id or losers_id.
For example:
wins = how many times their team_id is listed in the winners_id column of the games list.
I'm just not sure how to do this. Could someone help explain the best way to go about this? Am I on the right track of using a calc element in my list to calculate the win and loss record based on the number of times they appear in winner_id and loser_id column? Do you think their is a better / simpler way?
Thanks for any help!
I currently have a a fabrik application that keeps track of games and team records. Right now, a teams win loss record is updated after a game score is submitted. So after the game form is submitted, it calculates the winner based on score and adds a win to the win column of the teams record:
PHP:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
-> update('teams')
-> set('wins = wins + 1')
-> where('id = '. $db->quote($winning_team_name));
$db->setQuery($query);
$found = (int) $db->execute();
$query
-> clear()
-> update('teams')
-> set('losses = losses + 1')
-> where('id = '. $db->quote($losing_team_name));
$db->setQuery($query);
$found = (int) $db->execute();
The flaw with this is that it will perform every time the form is submitted. This will cause the form to perform an update on the win and loss column every time the forum is updated.
I think what I want to do is calculate the win and loss fields in my list view instead. I should create a winner_id and a loser_id element in my game list and the win loss field of each team should calculate how many times they appear in winners_id or losers_id.
For example:
wins = how many times their team_id is listed in the winners_id column of the games list.
I'm just not sure how to do this. Could someone help explain the best way to go about this? Am I on the right track of using a calc element in my list to calculate the win and loss record based on the number of times they appear in winner_id and loser_id column? Do you think their is a better / simpler way?
Thanks for any help!