<?php

session_start();
include "../config.php";
include "../header.php";
include "../style.php";
if( isset($_SESSION["alogin"]) ) {
    	?><table>
      	<tr>
        <td width="15%" valign=top><br>
        <? include("adminnavigation.php"); ?>
        </td>
        <td valign="top" align="center"><br><br> <?
    	echo "<font size=2 face='$fonttype' color='$fontcolour'><p><center>";

        echo "<center><H2>All winners in the database</H2></center>";

		
// how many rows to show per page
$rowsPerPage = 500;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;



        $query = "select * from game_winners ORDER BY date DESC LIMIT $offset, $rowsPerPage";
		$result = mysql_query ($query)
	     	or die ("Query failed");
        ?>
            <center><table width=70% border=0 cellpadding=2 cellspacing=2>
        	<tr>
			<td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Date</font></center></td>
	          <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Userid</font></center></td>
              <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Won</font></center></td>

	        </tr>
        <?
    	while ($line = mysql_fetch_array($result)) {
        	$id = $line["id"];
			$userid = $line["userid"];
            $won = $line["won"];

        ?><tr>
		<td bgcolor="<? echo $basecolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo date('Y-m-d', $line['date']); ?></font></center></td>
          <td bgcolor="<? echo $basecolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $userid; ?></font></center></td>
          <td bgcolor="<? echo $basecolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $won; ?></font></center></td>
          </td></tr> <?
        }
		echo '</table></center>';
		
		
		
		
		
		
		
		
		
 
$sql = mysql_query("SELECT * FROM game_winners");
$numrows = mysql_num_rows($sql);	
	
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = "viewallwinners.php?";


for($page = 1; $page <= $maxPage; $page++)
{
   if ($page == $pageNum)
   {
      echo " $page "; // no need to create a link to current page
   }
   else
   {
   
      echo " <a href=\"".$self."page=$page\">$page</a> ";
   }
}
		
		
		
		
		
		
		
        echo "<br><br></td></tr></table>";
    }
else
	echo "Unauthorised Access!";

include "../footer.php";

?>