<?php
	require("konf.php");
	mysql_connect($mysql_host, $mysql_user, $mysql_password);
	mysql_select_db($db);
  if(empty($ruut)){
  	header("Location: search.php?submit=Otsi&aeg=".$time);
    exit;
  }
?>
<html>
<head>
  <title>Valitud putukate andmed</title>
	<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
	<table width="100%">
  	<tr>
    	<td width="100%" align="center">
      	<table>
<?php
	$lae = mysql_query("SELECT id, liik, aeg, leidja, maaraja, piirkond, koht FROM bugs ORDER BY aeg DESC");
  while($row = mysql_fetch_array($lae)){
	  $row[2] = substr($row[2], 6, 2)."/".substr($row[2], 4, 2)."/".substr($row[2], 0, 4)."&nbsp;".substr($row[2], -4, 2).":".substr($row[2], -2);
    $MASS[$row[0]] = array($row[1], $row[3], $row[4], $row[5], $row[6], $row[2]);
	}
  $nimed = array("Liik", "Leidja", "Määraja", "Piirkond", "Koht", "Aeg");
  if(!empty($MASS)){
?>
          <caption>Valitud putukate andmed</caption>
	        <tr>
	          <td align="center">
	            <a href="search.php?submit=Otsi&aeg=<?php echo $time; ?>">Otsingulehele</a>
	            &nbsp;<a href="index.php">Esilehele</a>
	          </td>
	        </tr>
<?php
	  foreach($ruut as $r){
?>
        	<tr>
          	<td width="400" align="center">
            	<table style="border: 1px solid #000000; background-color: #F4F4F4">
<?php
			for($x=0;$x<6;$x++){
?>
              	<tr>
                	<td align="right" style="border: 1px solid #000000; background-color: #FFFFFF; font-style: italic"><?php echo $nimed[$x]; ?>:</td>
                	<td style="border: 1px solid #000000; background-color: #FFFFFF"><?php echo $MASS[$r][$x]; ?></td>
                </tr>
<?php
			}
?>
              </table>
            </td>
          </tr>
<?php
		}
	}else{
?>
					<tr>
          	<td class="NB">
            	Ei leitud ühtegi sisestust!
            </td>
          </tr>
<?php
	}
?>
        </table>
			</td>
    </tr>
  </table>
</body>
</html>