I have been struggling with this one for a couple days. I am trying to build a Joomla component that will display team standings based on record and then points for and points against. Currently I have the winning team of a game pushed into an array, but now trying to find a way to count the amount of times each specific name is in the array and display each teams record. For some reason this is really kicking my butt, any suggestions on what I am doing wrong or how to make it work is greatly appreciated.
$wins = array(); $loss = array(); $ties = array(); $db = Factory::getDBO(); $query = $db->getQuery( true ); $query = "SELECT s.id as id,s.hometeamid,s.awayteamid,b.finv,b.finh,ht.id as hometeamid,ht.name as hometeamname,at.id as awayteamid,at.name as awayteamname FROM #__football_schedule s INNER JOIN #__football_boxscore b ON b.gameid=s.id LEFT OUTER JOIN #__football_team ht ON ht.id = s.hometeamid LEFT OUTER JOIN #__football_team at ON at.id = s.awayteamid"; $db->setQuery( $query ); $schedules = $db->loadObjectList(); foreach ($schedules as $schedule) { if ($schedule->finh > $schedule->finv) { array_push($wins, $schedule->hometeamid, $schedule->finh); } if ($schedule->finv > $schedule->finh) { array_push($wins, $schedule->awayteamid); } if ($schedule->finh < $schedule->finv) { array_push($loss, $schedule->hometeamid, $schedule->finh); } if ($schedule->finv < $schedule->finh) { array_push($loss, $schedule->awayteamid); } if ($schedule->finv == $schedule->finh) { array_push($ties, $schedule->hometeamid and $schedule->awayteamid); } } Here is a SQL Fiddle with the above tables and some sample data.
ifconditions. Some subsequentifcan be ignored if an earlierifis satisfied -- in these cases, we should useelseifandelseconditions. Have a rethink about your pushing. Also, I am concerned about that lastarray_push()containingand-- I don't think you want this. Personally, I always use square brace syntax to push unless pushing multiple elements at one time.