function doit() { include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); $iAgeNumber = $objGame->get_game_time(AGE_NUMBER); include_once 'inc/classes/clsAge.php'; $objNewAge = new clsAge(); $objNewAge->loadAge($iAgeNumber); $iFirstYear = $objNewAge->getFirstYear(); $iLastYear = $objNewAge->getLastYear(); // Alla genom history $resSQL2 = mysql_query("SELECT year, alli_id, alli_name, alli_desc FROM rankings_history WHERE alli_id > 10 AND year >= {$iFirstYear} AND year <= {$iLastYear} GROUP BY year ASC"); // Lista Alla För att summera i PHP $old_id = 0; $count = 0; while ($arrRow = mysql_fetch_assoc($resSQL2)) { $new_id = $arrRow['alli_id']; if ($new_id != $old_id) { // prepare for new alliance $count++; // Copy SQL result row $arrAlliance[$count] = $arrRow; // add a starting year column to display period, eg 100 - 106 OE $arrAlliance[$count]['starting_year'] = $arrRow['year']; // add an ending year column to display period, eg 100 - 106 OE $arrAlliance[$count]['ending_year'] = $arrRow['year']; // add a year counter column, starting value = 1 $arrAlliance[$count]['years'] = 1; // Save alliance id for next loop $old_id = $new_id; } elseif ($new_id == $old_id) { // add another year to our counter column $arrAlliance[$count]['years']++; // update ending year column $arrAlliance[$count]['ending_year'] = $arrRow['year']; } } //====================================================================== // Sort the array //====================================================================== // Obtain the column to sorty by foreach ($arrAlliance as $key => $row) { $years[$key] = $row['starting_year']; } // Sort the data with years descending // Add $arrAlliance as the last parameter, to sort by the common key array_multisort($years, SORT_ASC, $arrAlliance); //====================================================================== // Done sorting ;) //====================================================================== echo "<h2>Timeline</h2>"; echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; $count = 1; foreach ($arrAlliance as $arrAlliance) { echo "<tr class=\"data\">"; echo "<td class=\"left\">(" . $arrAlliance['starting_year'] . ' - ' . $arrAlliance['ending_year'] . " OE) </td>"; echo "<th>" . stripslashes($arrAlliance['alli_name']) . "</th>"; echo "<td class=\"left\">" . "(#<A HREF=\"main.php?cat=game&page=alliance&aid=" . $arrAlliance['alli_id'] . "\">" . $arrAlliance['alli_id'] . "</A>)" . "</td>"; echo "<td>" . $arrAlliance['years'] . " years on top </td>"; $count++; echo "</tr>"; } echo "</table>"; }
function doit() { include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); $iAgeNumber = $objGame->get_game_time(AGE_NUMBER); include_once 'inc/classes/clsAge.php'; $objNewAge = new clsAge(); $objNewAge->loadAge($iAgeNumber); $iFirstYear = $objNewAge->getFirstYear(); $iLastYear = $objNewAge->getLastYear(); // Alla genom history $resSQL2 = mysql_query("SELECT year, alli_id, alli_name, alli_desc FROM rankings_history WHERE alli_id > 10 AND year >= {$iFirstYear} AND year <= {$iLastYear} GROUP BY year ASC"); // Lista Alla För att summera i PHP $old_id = 0; $iCount = 0; while ($arrRow = mysql_fetch_assoc($resSQL2)) { $new_id = $arrRow['alli_id']; if ($new_id != $old_id) { // prepare for new alliance $iCount++; // Copy SQL result row $arrAlliance[$iCount] = $arrRow; // add a starting year column to display period, eg 100 - 106 OE $arrAlliance[$iCount]['starting_year'] = $arrRow['year']; // add an ending year column to display period, eg 100 - 106 OE $arrAlliance[$iCount]['ending_year'] = $arrRow['year']; // add a year counter column, starting value = 1 $arrAlliance[$iCount]['years'] = 1; // Save alliance id for next loop $old_id = $new_id; } elseif ($new_id == $old_id) { // add another year to our counter column $arrAlliance[$iCount]['years']++; // update ending year column $arrAlliance[$iCount]['ending_year'] = $arrRow['year']; } } //====================================================================== // Sort the array //====================================================================== // Obtain the column to sorty by foreach ($arrAlliance as $key => $row) { $years[$key] = $row['starting_year']; } // Sort the data with years descending // Add $arrAlliance as the last parameter, to sort by the common key array_multisort($years, SORT_ASC, $arrAlliance); //====================================================================== // Done sorting ;) //====================================================================== // echo '<div class="center"><h2>Timeline</h2></div>'; echo '<br />'; $strTimelineCurrentTable = '<table class="big" cellpadding="0" cellspacing="0">' . '<tr class="header">' . '<th colspan="5">Timeline</th>' . '</tr>' . '<tr class="subheader">' . '<th>Period</th>' . '<th>Alliance Name</th>' . '<th>Alliance Description</th>' . '<th>#</th>' . '<th class="right">Years</th>' . '</tr>'; $iCount = 1; foreach ($arrAlliance as $arrAlliance) { $strTimelineCurrentTable .= '<tr class="data">' . '<td class="left">(' . $arrAlliance['starting_year'] . ' - ' . $arrAlliance['ending_year'] . ' OE) </td>' . '<th>' . stripslashes($arrAlliance['alli_name']) . '</th>' . '<td class="left">' . stripslashes($arrAlliance['alli_desc']) . '</td>' . '<td class="left">' . '(#<a href="main.php?cat=game&page=alliance&aid=' . $arrAlliance['alli_id'] . '">' . $arrAlliance['alli_id'] . '</a>)</td>' . '<td>' . $arrAlliance['years'] . ' years on top </td>' . '</tr>'; $iCount++; } $strTimelineCurrentTable .= '</table>'; echo $strTimelineCurrentTable; }